MATLAB Function Reference |
Syntax
Description
tf = isequal(A, B, ...)
returns logical 1
(true
) if the input arrays are the same type and size and hold the same contents, and logical 0
(false
) otherwise.
Remarks
When comparing structures, the order in which the fields of the structures were created is not important. As long as the structures contain the same fields, with corresponding fields set to equal values, isequal
considers the structures to be equal. See Example 2, below.
When comparing numeric values, isequal
does not consider the data type used to store the values in determining whether they are equal. See Example 3, below.
NaN
s (Not a Number), by definition, are not equal. Therefore, arrays that contain NaN
elements are not equal, and isequal
returns zero when comparing such arrays. See Example 4, below. Use the isequalwithequalnans
function when you want to test for equality with NaN
s treated as equal.
isequal
recursively compares the contents of cell arrays and structures. If all the elements of a cell array or structure are numerically equal, isequal
returns logical 1
.
Example 1
isequal(A,B,C)
returns 0
, and isequal(A,B)
returns 1
.
Example 2
When comparing structures with isequal
, the order in which the fields of the structures were created is not important:
Example 3
When comparing numeric values, the data types used to store the values are not important:
Example 4
Arrays that contain NaN
(Not a Number) elements cannot be equal, since NaN
s, by definition, are not equal:
See Also
isequalwithequalnans
, strcmp
, isa
, is*, relational operators
isempty | isequalwithequalnans |
© 1994-2005 The MathWorks, Inc.