getting elements of a vector

1 visualización (últimos 30 días)
Salvatore Mazzarino
Salvatore Mazzarino el 8 de Nov. de 2012
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

Respuesta aceptada

Andrei Bobrov
Andrei Bobrov el 8 de Nov. de 2012
Editada: Andrei Bobrov el 8 de Nov. de 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 comentarios
Salvatore Mazzarino
Salvatore Mazzarino el 8 de Nov. de 2012
It isn't what I asked
Salvatore Mazzarino
Salvatore Mazzarino el 8 de Nov. de 2012
Ok the second answer resolved my problem. Thanks so much

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Data Types en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by