matlab - Finding elements in an array other than given indices -
i want find elements in array not given index elements. example, given array a = [1 5 7 8]
, , index ind = [2 3]
, operation should return elements [1 8]
.
use 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));
Comments
Post a Comment