getting elements of a vector

조회 수: 1 (최근 30일)
Salvatore Mazzarino
Salvatore Mazzarino 2012년 11월 8일
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

채택된 답변

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

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by