b
to a
and
c
using logical operators, e.g. <
,
>=
, ==
, etc.
Instead, MATLAB evaluates operators of equal precedence from left to right.
This means that the statement, a < b < c
, is equivalent
to the statement (a < b) < c
, comparing the logical
result of a < b
(either 0
or
1
) to the value c
. Statements using
this type of interval testing rarely yield useful results.
Break the comparison, a < b < c
, into a series of
binary comparisons. If all arguments are numeric scalars, use the
form:(a < b) && (b < c)
Otherwise,
use the form:(a < b) & (b < c)
For more information, see Operator Precedence.