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: IF (simple coding problem)
Replies: 4   Last Post: Feb 11, 2013 2:31 PM

Advanced Search

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

Posts: 977
Registered: 12/7/04
Re: IF (simple coding problem)
Posted: Feb 11, 2013 2:31 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply


"Chris Mc" <remove.this.c.mccorquodale@axon-cable.co.uk> wrote in message
news:kfavh1$dfq$1@newscl01ah.mathworks.com...
> Hi,
>
> I am having troulbe using the IF operator. Logically, what I am doing
> makes sense but it doesn't give the correct output so obviously somethings
> going wrong. Trying to keep it simple (so as not to confuse things), when
> I input:
>
> T=301
> if 290<T<300
> a=1
> else
> a=2
> end
>
> It always give me a=1?? To me, this code says if T is between 290 and 300
> (which it isn't) a=1, any other value and a=2. Why then is it giving me
> a=1 and how can I rectify this? Is it something to do with the '<'
> symbols?


See this blog post:
http://blogs.mathworks.com/loren/2012/05/14/why-is-answer-to-3-a-7-unexpected/


--
Loren
http://blogs.mathworks.com/loren/
http://www.mathworks.com/matlabcentral/




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.