Set indexes not in list to zero.

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?

Tags

Asked:

on 15 May 2013

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!