eq
Equality test, the function form of the == operator.
Category: Programming > Classes
Syntax
C = eq(A, B)
Compares A and B element by element. Same as A == B.
Description
The comparison converts to a common type first, so eq(true, 1) and eq('a', 97) are both true. A scalar is compared against every element of an array. Two NaN values are never equal, and comparing a number to a NaN gives false.
For handle objects, eq tests whether both operands are the same object, not whether their contents match. Floating-point results that look equal can differ in the last digits, so for computed values compare with a tolerance, abs(a - b) < tol. To compare whole arrays, use isequal.
Input arguments
A, B- Numeric, logical or char arrays, or objects. Sizes must be compatible (equal, or one of them is 1 in each dimension).
Output arguments
C- Logical array:
truewhere the elements are equal.
Example
Elementwise and scalar comparison
eq([1 2 3], [1 5 3])
eq([1 2 2; 2 3 2], 2)
eq('abc', 'abd')
eq([1 NaN], [1 NaN])
Output
ans = 1×3 logical array
1 0 1
ans = 2×3 logical array
0 1 1
1 0 1
ans = 1×3 logical array
1 1 0
ans = 1×2 logical array
1 0
Notes
Comparing structs or cell arrays with eq is an error, as in MATLAB.