Set indexes not in list to zero.
Show older comments
I have a large vector d and a list of indices k where k<d. I wish to set points in d that are not in the list k to zero. I can achieve this with the following code.
d2=zeros(length(d),1);
d2(k)=d(k);
However, creating a new vector causes memory problems because of the size of d. Is there a way to achieve this without creating a new vector?
Answers (1)
Azzi Abdelmalek
on 15 May 2013
d(setdiff(1:numel(d),k))=0
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!