Accelerating the pace of engineering and science

# isequaln

Determine array equality, treating NaN values as equal

## Description

example

tf = isequaln(A,B) returns logical 1 (true) if A and B are the same size and their contents are of equal value; otherwise, it returns logical 0 (false). The test compares both real and imaginary parts of numeric arrays. isequaln ignores the data type of the values in determining whether they are equal. For cell arrays, categorical arrays, tables, or structures, the function returns logical 1 (true) only when all elements and properties are equal. Undefined categorical elements, NaN (Not a Number), or NaT (Not a Time) values are considered to be equal to other such values.

example

tf = isequaln(A1,A2,...,An) returns logical 1 (true) if all the inputs are numerically equal.

## Examples

expand all

### Compare Two Numeric Matrices

Create two numeric matrices and compare them for equality.

```A = zeros(3,3)+1e-20;
B = zeros(3,3);
tf = isequaln(A,B)
```
```tf =

0```

The function returns logical 0 (false) because the matrices differ by a very small amount and are not exactly equal.

### Compare Two Structures

Create two structures and specify the fields in a different order.

```A = struct('field1',0.005,'field2',2500);
B = struct('field2',2500,'field1',0.005);
```

Compare the structures for equality.

```tf = isequaln(A,B)
```
```tf =

1```

Even though the ordering of the fields in each structure is different, isequaln treats them as the same because the values are equal.

### Comparing Numeric Values with Special Nonnumeric Values

Compare the logical value true to the double integer 1.

```isequaln(true,1)
```
```ans =

1```

Notice that isequaln does not consider data type when it tests for equality.

Similarly, compare 'A' to the ASCII-equivalent integer, 65.

```isequaln('A',65)
```
```ans =

1```

The result is logical 1 (true) since double('A') equals 65.

### Compare Vectors Containing NaN Values

Create three vectors containing NaN values.

```A1 = [1 NaN NaN];
A2 = [1 NaN NaN];
A3 = [1 NaN NaN];
```

Compare the vectors for equality.

```tf = isequaln(A1,A2,A3)
```
```tf =

1```

The result is logical 1 (true) because isequaln treats the NaN values as equal to each other.

## Input Arguments

expand all

### A,B — Inputs to be comparednumeric arrays | categorical arrays | cell arrays | tables | structures | ...

Inputs to be compared, specified as numeric arrays, categorical arrays, cell arrays, tables, or structures. Also, you can specify the inputs as logical arrays, character arrays, datetime arrays, duration arrays, calendarDuration arrays, or objects. The numeric types of A and B do not have to match.

You can compare a categorical array to a cell array of strings of the same size, or a single categorical element to a single string.

You can compare a datetime array to a cell array of date strings or a single date string.

If inputs A and B are both

• Structures -- Fields need not be in the same order as long as the contents are equal.

• Ordinal categorical arrays -- Must have the same sets of categories, including their order.

• Categorical arrays that are not ordinal -- Can have different sets of categories, and isequaln compares the category names of each pair of elements.

• Datetime arrays -- isequal ignores time zone and display format when it compares points in time.

• Objects of different classes -- isequaln returns logical 0 (false). This applies even when the objects have the same properties and their values match.

### A1,A2,...,An — Series of inputs to be comparednumeric arrays | categorical arrays | cell arrays | tables | structures | ...

Series of inputs to be compared, specified as numeric arrays, categorical arrays, cell arrays, tables, or structures. Also, you can specify the inputs as logical arrays, character arrays, datetime arrays, duration arrays, calendarDuration arrays, or objects. The numeric types of the inputs do not have to match.

You can compare categorical arrays to cell arrays of strings of the same size, or single categorical elements to single strings.

You can compare a datetime array to a cell array of date strings or a single date string.

If the inputs are all

• Structures -- Fields need not be in the same order as long as the contents are equal.

• Ordinal categorical arrays -- Must have the same sets of categories, including their order.

• Categorical arrays that are not ordinal -- Can have different sets of categories, and isequaln compares the category names of each pair of elements.

• Datetime arrays -- isequaln ignores time zone and display format when it compares points in time.

• Objects of different classes -- isequaln returns logical 0 (false). This applies even when the objects have the same properties and their values match.