フィルターのクリア

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 Center および File ExchangeMatrix Indexing についてさらに検索

製品


リリース

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by