From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: For/If statement monitoring position of item
Date: Thu, 8 Mar 2012 03:22:17 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 12
Message-ID: <jj98l9$lgm$>
References: <jj946k$954$>
Reply-To: <HIDDEN>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: 1331176937 22038 (8 Mar 2012 03:22:17 GMT)
NNTP-Posting-Date: Thu, 8 Mar 2012 03:22:17 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: comp.soft-sys.matlab:760292

"Jacob " <> wrote in message <jj946k$954$>...
> .....
> .....  The code i wrote changes the payment status to 1 regardless of location, and I'm not sure what i did wrong. .....
> .....
>         if payXlimMin < P1X(i) < payXlimMax && payYlimMin < P1Y(i) < payYlimMax
> .....
- - - - - - - -
  When you write "a<b<c" as you have, it can give you very unexpected results.  Very likely you want it to mean "a is less than b and b is less than c", but that is not how matlab interprets it.  It groups things this way: (a<b)<c and first determines whether a<b is true or false.  Then since (a<b) looks to matlab as though it were a numerical quantity because it occurs in another inequality, it converts the true/false state to a 1 or 0, respectively, and determines whether that 1 or 0 is numerically less than c.  This is very far from what you undoubtedly had in mind.

  Always write (a<b)&(b<c) and never a<b<c to avoid catastrophes like this.

Roger Stafford