All index values expect certain indices

2 views (last 30 days)
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

Accepted Answer

Bruno Luong
Bruno Luong on 27 Nov 2018
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

More Answers (0)

Products


Release

R2017b

Community Treasure Hunt

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

Start Hunting!