next up previous contents
Next: LOGICALOPS Logical Array Operators Up: Mathematical Operators Previous: DOTPOWER Element-wise Power Operator   Contents

Subsections

COMPARISONOPS Array Comparison Operators

Usage

There are a total of six comparison operators available in FreeMat, all of which are binary operators with the following syntax

  y = 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:

  1. a is a scalar, b is an n-dimensional array - the output is then the same size as b, and contains the result of comparing each element in b to the scalar a.
  2. a is an n-dimensional array, b is a scalar - the output is the same size as a, and contains the result of comparing each element in a to the scalar b.
  3. a and b are both n-dimensional arrays of the same size - the output is then the same size as both a and b, and contains the result of an element-wise comparison between a and b.
The operators behave the same way as in C, with unequal types meing 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 = 
  <double>  - size: [1 5]
 
Columns 1 to 2
   -0.0361639933961680       -0.140415140955028      
 
Columns 3 to 4
    0.693389551907565        -0.238187257168569      
 
Columns 5 to 5
    0.599755385896831      
--> a>0
ans = 
  <logical>  - size: [1 5]
 
Columns 1 to 5
 0  0  1  0  1

Next, we construct two vectors, and test for equality:

--> a = [1,2,5,7,3]
a = 
  <int32>  - size: [1 5]
 
Columns 1 to 5
             1              2              5              7              3  
--> b = [2,2,5,9,4]
b = 
  <int32>  - size: [1 5]
 
Columns 1 to 5
             2              2              5              9              4  
--> c = a == b
c = 
  <logical>  - size: [1 5]
 
Columns 1 to 5
 0  1  1  0  0


next up previous contents
Next: LOGICALOPS Logical Array Operators Up: Mathematical Operators Previous: DOTPOWER Element-wise Power Operator   Contents
Samit K. Basu 2005-03-16