COMPARISONOPS Array Comparison Operators
Section: Mathematical Operators
Usage
There are a total of six comparison operators available in FreeMat, all of which are binary operators with the following syntaxy = a < b y = a <= b y = a > b y = a >= b y = a ~= b y = a == b
where a
and b
are numerical arrays or scalars, and y
is a logical
array of the appropriate size. Each of the operators has three modes of operation, summarized in the following list:
-
a
is a scalar,b
is an n-dimensional array - the output is then the same size asb
, and contains the result of comparing each element inb
to the scalara
. -
a
is an n-dimensional array,b
is a scalar - the output is the same size asa
, and contains the result of comparing each element ina
to the scalarb
. -
a
andb
are both n-dimensional arrays of the same size - the output is then the same size as botha
andb
, and contains the result of an element-wise comparison betweena
andb
.
C
, with unequal types being promoted using the standard type promotion rules prior to comparisons. The only difference is that in FreeMat, the not-equals operator is ~=
instead of !=
.
Examples
Some simple examples of comparison operations. First a comparison with a scalar:--> a = randn(1,5) a = -0.1760 0.0212 0.0095 2.0556 -1.1627 --> a>0 ans = 0 1 1 1 0
Next, we construct two vectors, and test for equality:
--> a = [1,2,5,7,3] a = 1 2 5 7 3 --> b = [2,2,5,9,4] b = 2 2 5 9 4 --> c = a == b c = 0 1 1 0 0