Reputation: 123
I want to find the elements in an array which are not the given index elements. For example, given an array A = [1 5 7 8]
, and index ind = [2 3]
, the operation should return elements [1 8]
.
Upvotes: 0
Views: 39
Reputation: 35080
Use a direct index vector:
B = A(setdiff(1:numel(A),ind));
Or throw away unneeded elements:
B = A;
B(ind) = [];
Or use logical indexing:
% either
B = A(~any(bsxfun(@eq,ind(:),1:numel(A)),1));
% or
B = A(all(bsxfun(@ne,ind(:),1:numel(A)),1));
Upvotes: 2