Array Comparison with Relational Operators
In this section...
“Array Comparison” on page 2-25
“Logic Statements” on page 2-28
Relational operators compare operands quantitatively, using operators like “less than”,
“greater than”, and “not equal to.” The result of a relational comparison is a logical array
indicating the locations where the relation is true.
These are the relational operators in MATLAB.
Symbol Function Equivalent Description
< lt Less than
<= le Less than or equal to
> gt Greater than
>= ge Greater than or equal to
== eq Equal to
~= ne Not equal to
Array Comparison
Numeric Arrays
The relational operators perform element-wise comparisons between two arrays. The
arrays must have compatible sizes to facilitate the operation. Arrays with compatible sizes
are implicitly expanded to be the same size during execution of the calculation. In the
simplest cases, the two operands are arrays of the same size, or one is a scalar. For more
information, see “Compatible Array Sizes for Basic Operations” on page 2-19.
For example, if you compare two matrices of the same size, then the result is a logical
matrix of the same size with elements indicating where the relation is true.
A = [2 4 6; 8 10 12]
A =
Array Comparison with Relational Operators