필터 지우기
필터 지우기

All index values expect certain indices

조회 수: 2 (최근 30일)
Niels de Vries
Niels de Vries 2018년 11월 27일
답변: Bruno Luong 2018년 11월 27일
Hey all,
My question is as follows: how can i select all the index values except for certain indices. Let's consider the following example:
A = [5 6 7 8]
x{1} = [1];
x{2} = [1 2];
x{3} = [2 3 4];
Now i want to select the values of A except for the indices in x, so the output should be:
[6 7 8]
[7 8]
[5]
I tried the following code (which does not work), does someone knows how to do this ?
for i = 1:3
A(1:end ~= x{i})
end
Thanks in advance

채택된 답변

Bruno Luong
Bruno Luong 2018년 11월 27일
A = [5 6 7 8];
x{1} = [1];
x{2} = [1 2];
x{3} = [2 3 4];
c = cellfun(@(i) A(setdiff(1:end,i)), x, 'unif', 0)
c{:}
That gives:
ans =
6 7 8
ans =
7 8
ans =
5

추가 답변 (0개)

카테고리

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

제품


릴리스

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by