MATLAB Function Reference  Relational Operators < > <= >= == ~=

Relational operations

Syntax

• ```A < B
A > B
A <= B
A >= B
A == B
A ~= B
```

Description

The relational operators are `<`, `>`, `<=`, `>=`, `==`, and `~=`. Relational operators perform element-by-element comparisons between two arrays. They return a `logical` array of the same size, with elements set to logical `1` (`true`) where the relation is true, and elements set to logical `0` (`false`) where it is not.

The operators `<`, `>`, `<=`, and `>=` use only the real part of their operands for the comparison. The operators `==` and `~=` test real and imaginary parts.

To test if two strings are equivalent, use `strcmp`, which allows vectors of dissimilar length to be compared.

 Note    For some toolboxes, the relational operators are overloaded, that is, they perform differently in the context of that toolbox. To see the toolboxes that overload a given operator, type `help` followed by the operator name. For example, type `help lt`. The toolboxes that overload `lt (<)` are listed. For information about using the operator in that toolbox, see the documentation for the toolbox.

Examples

If one of the operands is a scalar and the other a matrix, the scalar expands to the size of the matrix. For example, the two pairs of statements

• ```X = 5; X >= [1 2 3; 4 5 6; 7 8 10]
X = 5*ones(3,3); X >= [1 2 3; 4 5 6; 7 8 10]
```

produce the same result:

• ```ans =

1    1    1
1    1    0
0    0    0
```

See Also

`all`, `any`, `find`, `strcmp`

Elementwise Logical Operators, `&`, `|`, Short-Circuit Logical Operators, `&&`, `||`, `~` Arithmetic Operators + - * / \ ^ ' Logical Operators: Elementwise & | ~ © 1994-2005 The MathWorks, Inc.