==
Equality operator: tests element by element whether A and B are equal.
Category: Language Fundamentals > Operators and Elementary Operations
Syntax
C = A == B
Applies the operator to A and B. Same as eq(A, B).
Description
The test is element-wise with implicit expansion, and NaN is never equal to anything, itself included. To compare whole arrays as one yes or no answer use isequal.
For char arrays the comparison is per character, so the two strings must have the same length or one must be a single character. Use strcmp to compare text as a whole.
Input arguments
A, B- Numeric, logical or char arrays (only the real part is compared for complex values). Sizes must be compatible, or one of them a scalar.
Output arguments
C- Logical array:
1where the relation holds,0elsewhere.
Example
[1 2 3] == [1 5 3]
'hello' == 'l'
NaN == NaN
isequal([1 2 3], [1 2 3])
Output
ans = 1×3 logical array
1 0 1
ans = 1×5 logical array
0 0 1 1 0
ans = logical
0
ans = logical
1
Notes
Floating-point results that look equal can differ in the last bits, for example 0.1 + 0.2 == 0.3 is 0.