Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: keep values in a range (e.g. >2 & <6) in a matrix
Replies: 2   Last Post: Feb 18, 2013 2:11 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
dpb

Posts: 8,248
Registered: 6/7/07
Re: keep values in a range (e.g. >2 & <6) in a matrix
Posted: Feb 18, 2013 1:44 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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
>>

--




Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.