Path: news.mathworks.com!not-for-mail 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$1@newscl01ah.mathworks.com> References: <jj946k$954$1@newscl01ah.mathworks.com> Reply-To: <HIDDEN> NNTP-Posting-Host: www-02-blr.mathworks.com Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Trace: newscl01ah.mathworks.com 1331176937 22038 172.30.248.47 (8 Mar 2012 03:22:17 GMT) X-Complaints-To: news@mathworks.com NNTP-Posting-Date: Thu, 8 Mar 2012 03:22:17 +0000 (UTC) X-Newsreader: MATLAB Central Newsreader 1187260 Xref: news.mathworks.com comp.soft-sys.matlab:760292 "Jacob " <jblank@tulane.edu.removethis> wrote in message <jj946k$954$1@newscl01ah.mathworks.com>... > ..... > ..... 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