isequal
Tests whether arrays are equal in size and content.
Category: Language Fundamentals > Operators and Elementary Operations
Syntax
tf = isequal(A, B)
Returns true if A and B have the same size and equal elements.
tf = isequal(A, B, C, ...)
Returns true if all the arguments are equal to each other.
Description
Unlike ==, which compares element by element and returns an array, isequal gives one yes-or-no answer for the whole value, and arrays of different sizes simply compare as not equal. Numeric values are compared by value regardless of class, so isequal(1, int8(1)) is true; char compares by character code.
Every NaN is different from every other, so arrays holding NaN are never equal. Use isequaln to treat NaN values as equal. Structs and cell arrays are compared recursively.
Input arguments
A, B, ...- Values of any type: numeric arrays, text, cell arrays, structs and so on.
Output arguments
tf- A single logical scalar.
Example
isequal([1 2 3], [1 2 3])
isequal([1 2 3], [1 2 3 4])
isequal(1, int8(1))
isequal([1 NaN], [1 NaN])
isequal(struct('a', 1), struct('a', 1))
Output
ans = logical
1
ans = logical
0
ans = logical
1
ans = logical
0
ans = logical
1