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: Vector comparison using if
Replies: 4   Last Post: Nov 20, 2012 4:04 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Rajasekhara Madhusudan Narayana Bhatla

Posts: 2
Registered: 11/19/12
Re: Vector comparison using if
Posted: Nov 20, 2012 12:33 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"Nasser M. Abbasi" <nma@12000.org> wrote in message <k8eq0v$u39$1@speranza.aioe.org>...
> On 11/19/2012 7:52 PM, Rajasekhara Madhusudan Narayana Bhatla wrote:
> > Hi,
> > I'm sought of new using matlab. I've a situation where I've to assign a variable 2 different values based on how the values in vector
> >
> > it is something like.
> > fs=1000;
> > x=1:4/fs:5;
> > if x<2
> > Y=x.^2
> > else
> > Y=4;
> > end.
> >
> > i.e, my Y will also be a vector whose value depends on where I x is. if x is <2
> >then y is x^2 if not it is a constant.
> >
> > I'm not sure how to do this.
> > i tried it with if any(x)<2 but I then i realized that it is not correct.
> >since I want for all values of x<2 Y=x^2 and all values of x >2 x = 4.
> >
> > Please Help,
> >
> > Thanks,
> > Sekhar.
> >

>
> many ways to do this. One way
>
> ----------------
> fs = 1000;
> x = 1:4/fs:5;
> Y = 4*ones(length(x),1);
> Y(x<2) = x(x<2).^2
> ------------------
>
> --Nasser


Ok...got it...
Thanks a lot.

if possible can you give me some pointers as to what are other ways.

Thanks,
Sekhar.



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.