Skip to Main Content Skip to Search
Product Documentation

isequalwithequalnans - Test arrays for equality, treating NaNs as equal

Syntax

tf = isequalwithequalnans(A, B, ...)

Description

tf = isequalwithequalnans(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. NaN (Not a Number) values are considered to be equal to each other. Numeric data types and structure field order do not have to match.

Tips

isequalwithequalnans is the same as isequal, except isequalwithequalnans considers NaN (Not a Number) values to be equal, and isequal does not.

isequalwithequalnans recursively compares the contents of cell arrays and structures. If all the elements of a cell array or structure are numerically equal, isequalwithequalnans returns logical 1.

Examples

Arrays containing NaNs are handled differently by isequal and isequalwithequalnans. isequal does not consider NaNs to be equal, while isequalwithequalnans does.

A = [32 8 -29 NaN 0 5.7];
B = A;
isequal(A, B)
ans =
     0

isequalwithequalnans(A, B)
ans =
     1

The position of NaN elements in the array does matter. If they are not in the same position in the arrays being compared, then isequalwithequalnans returns zero.

A = [2 4 6 NaN 8];   B = [2 4 NaN 6 8];
isequalwithequalnans(A, B)
ans =
     0

See Also

is* | isa | isequal | isequaln | relational operators | strcmp

  


Free MATLAB Interactive Kit

Explore how to use MATLAB to make advancements in engineering and science.


Download free kit

Trials Available

Try the latest version of MATLAB and other MathWorks products.


Get trial software
 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS