| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → MATLAB |
| Contents | Index |
| Learn more about MATLAB |
tf = isequal(A, B, ...)
tf = isequal(A, B, ...) returns logical 1 (true) if the input arrays have the same contents, and logical 0 (false) otherwise. Nonempty arrays must be of the same data type and size.
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. This is also true when comparing numeric values with certain nonnumeric values, such as logical true and 1, or the character A and its numeric equivalent, 65.
NaNs (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 NaNs 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.
Given
A = B = C =
1 0 1 0 1 0
0 1 0 1 0 0
isequal(A,B,C) returns 0, and isequal(A,B) returns 1.
When comparing structures with isequal, the order in which the fields of the structures were created is not important:
A.f1 = 25; A.f2 = 50
A =
f1: 25
f2: 50
B.f2 = 50; B.f1 = 25
B =
f2: 50
f1: 25
isequal(A, B)
ans =
1When comparing numeric values, the data types used to store the values are not important:
A = [25 50]; B = [int8(25) int8(50)];
isequal(A, B)
ans =
1Arrays that contain NaN (Not a Number) elements cannot be equal, since NaNs, by definition, are not equal:
A = [32 8 -29 NaN 0 5.7];
B = A;
isequal(A, B)
ans =
0isequalwithequalnans, strcmp, isa, is*, relational operators
![]() | isempty (tscollection) | isequal (MException) | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |