All index values expect certain indices
2 views (last 30 days)
Show older comments
Niels de Vries
on 27 Nov 2018
Answered: Bruno Luong
on 27 Nov 2018
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
0 Comments
Accepted Answer
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
0 Comments
More Answers (0)
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!