Set indexes not in list to zero.
Ältere Kommentare anzeigen
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?
Antworten (1)
Azzi Abdelmalek
am 15 Mai 2013
d(setdiff(1:numel(d),k))=0
Kategorien
Mehr zu Matrix Indexing finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!