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



Re: 3 condition in IF statement
Posted:
Aug 1, 2013 8:31 AM


"Babak " <b_mn@hotmail.com> wrote in message news:kt9ee8$bt7$1@newscl01ah.mathworks.com... > "Roger Stafford" wrote in message > <kt9dkd$a5l$1@newscl01ah.mathworks.com>... >> "Babak " <b_mn@hotmail.com> wrote in message >> <kt96mq$m84$1@newscl01ah.mathworks.com>... >> > > > if ((0>=f1<=2) && (4>=f2<=5) && (1>=THD<=6)) >>        >> 'Someone' is right. Strictly speaking, that notation is allowed, but >> it is interpreted in the following remarkable way. In "4>=f2<=5" suppose >> f2 = 6. Then the expression is parsed as: >> >> (4>=f2)<=5 >> >> The "4>=f2" portion would be false which gives "false<=5", but since the >> "<=" demands numerical values at either end, the 'false' is translated to >> a numerical 0, which gives "0<=5" and that is actually true. However >> this is certainly not what one would expect in such a case. >> >> Many people have been tripped up by this kind of unintended result. >> The obvious remedy is to never, never use expressions of a form similar >> to a<=b<=c in matlab. >> >> Roger Stafford > > Very interesting! Thank you for more info,nowhere I could find such info
I wrote about this on my blog last year:
http://blogs.mathworks.com/loren/2012/05/14/whyisanswerto3a7unexpected/
 Loren
http://blogs.mathworks.com/loren



