getting elements of a vector
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have this vector
g_counter = [5 6 9 0 0];
list = [1 2 3];
If I do
g_counter(list)
I get 5 6 9 instead I would get 0 0. I would obtain complementary elements
0 commentaires
Réponse acceptée
Andrei Bobrov
le 8 Nov 2012
Modifié(e) : Andrei Bobrov
le 8 Nov 2012
g_counter = [5 6 9 0 0];
out = g_counter(g_counter == 0);
or
g_counter = [5 6 9 0 0];
list = [1 2 3];
out = g_counter(setdiff(1:numel(g_counter),list));
or
g_counter = [5 6 9 0 0];
list = [1 2 3];
t = true(size(g_counter));
t(list) = false;
out = g_counter(t);
2 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Data Types dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!