In MATLAB, you can use the logical AND operator &
to check if a value falls within a certain range. For example, to test if a variable x
is between 0 and 1 exclusive, you could use the following condition:
main.m96 chars6 lines
Alternatively, you could use the double-ampersand &&
operator for a short-circuiting evaluation of the same condition:
main.m97 chars6 lines
Notice that using &&
can sometimes be faster, because it stops evaluating the condition as soon as it decides the truth value (i.e., if x
is less than or equal to 0, it won't bother checking if it's less than 1).
Note that if x
can take on non-finite or complex values, you may need to use the isnan
or isinf
functions to check for those cases before applying the range condition.
gistlibby LogSnag