Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
Drexel University or The Math Forum.


dpb
Posts:
8,648
Registered:
6/7/07


Re: keep values in a range (e.g. >2 & <6) in a matrix
Posted:
Feb 18, 2013 1:44 PM


On 2/18/2013 12:35 PM, Albert Drif wrote: > Hi, > For instance, the code starts with > x1=[1 2 3;4 5 6]; > x2 = NaN.*ones(size(x1)) > [row col] = find(x1>2 & x1<6); > > I want to get a matrix x2 = [NaN NaN 3; 4 5 NaN] which keeps the shape > of x1. I tried x2([row col]) = x1([row col]) > but it gave me x2 = > > 1 2 NaN > 4 NaN NaN > which is opposite to what I want...
>> x1=reshape([1:6],3,2)'; >> x1((x1<3)  (x1>5))=nan x1 = NaN NaN 3 4 5 NaN >>




