Previous Page | Next Page

 Language Reference

## Logical Operators:   &   |   ^

perform elementwise logical comparisons

matrix1&matrix2
matrix&scalar
matrix&vector
matrix1|matrix2
matrix|scalar
matrix|vector
^matrix

The AND logical operator (&) compares two matrices, element by element, to produce a new matrix. An element of the new matrix is 1 if the corresponding elements of matrix1 and matrix2 are both nonzero; otherwise, it is a zero.

An element of the new matrix produced by the OR operator (|) is 1 if either of the corresponding elements of matrix1 and matrix2 is nonzero. If both are zero, the element is zero.

If either operand is a scalar, the operator does the logical operation for each element and the scalar value. If either operand is a row or column vector, then the operation is performed using that vector on each of the rows or columns of the matrix.

The NOT prefix operator (^) examines each element of a matrix and produces a new matrix containing elements that are ones and zeros. If an element of matrix equals 0, the corresponding element in the new matrix is 1. If an element of matrix is nonzero, the corresponding element in the new matrix is 0.

The following statements illustrate the use of these logical operators:

```
z=x&r;
if a|b then print c;