how to delete adjacent entries from an array
Show older comments
Hallo,
I have a long column vector A (say 30000x1) with values 1 to 100 and I want not only to delete all entries equal to the number 60 (which I can do with B= A(A~=60), but all 50 elements immediately next to 60 (previous and next, in total 100). The elements in A are randomly positioned , so some times the deleted values may 'overlap'. Do you know how I can do this?
Thank you
Accepted Answer
More Answers (1)
Andrei Bobrov
on 13 Feb 2014
Edited: Andrei Bobrov
on 13 Feb 2014
ii = unique(bsxfun(@plus,find(A == 60),[-1 0 1]));
out = A;
out(ii(ii > 0 & ii <= numel(A))) = [];
way with Image Processing Toolbox
out = A(imerode(A ~= 60,[1;1;1]));
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!