Sunday, 15 July 2012

Replacing elements of variable in Matlab -



Replacing elements of variable in Matlab -

how can replace every element in variable info less 0.5 0.

i tried this, it's not working.

rng(110) data= rand(1, 1e8); tstart = tic; count = (data<0.5); replace = replacedata(data,count,0); telapsed = toc(tstart);

what replacedata?? quite basic matlab using logical indexing so:

data(data < 0.5) = 0

or alternatively:

replace = data.*(data < 0.5) %// works because replacing value 0 matlab automatically casts logical matrices doubles when using arithmetic.

matlab

No comments:

Post a Comment