MATLAB Answers

getting elements of a vector

1 ビュー (過去 30 日間)
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 件のコメント

Sign in to comment.

採用された回答

Andrei Bobrov
Andrei Bobrov 2012 年 11 月 8 日
編集済み: Andrei Bobrov 2012 年 11 月 8 日
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 件のコメント

Salvatore Mazzarino
Salvatore Mazzarino 2012 年 11 月 8 日
It isn't what I asked
Salvatore Mazzarino
Salvatore Mazzarino 2012 年 11 月 8 日
Ok the second answer resolved my problem. Thanks so much

Sign in to comment.

その他の回答 (0 件)


Translated by