Documentation

This is machine translation

Translated by Microsoft
Mouse over text to see original. Click the button below to return to the English verison of the page.

라이선스가 부여된 사용자만 번역 문서를 볼 수 있습니다. 번역 문서를 보려면 로그인하십시오.

isequal

Determine array equality

Syntax

Description

example

tf = isequal(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. isequal 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, <missing>, NaN (Not a Number), or NaT (Not a Time) values are considered to be unequal to other elements, as well as themselves.

example

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

Examples

collapse all

Create two numeric matrices and compare them for equality.

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

  logical

   0

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

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 = isequal(A,B)
tf =

  logical

   1

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

Compare the logical value true to the double integer 1.

isequal(true,1)
ans =

  logical

   1

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

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

isequal('A',65)
ans =

  logical

   1

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

Create three vectors containing NaN values.

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

Compare the vectors for equality.

tf = isequal(A1,A2,A3)
tf =

  logical

   0

The result is logical 0 (false) because isequal does not treat NaN values as equal to each other.

Determine if midnight on January 13, 2013 in Anchorage, Alaska is equal to 11 AM on the same date in Cairo.

t1 = datetime(2013,1,13,0,0,0,'TimeZone','America/Anchorage');
t2 = datetime(2013,1,13,11,0,0,'TimeZone','Africa/Cairo');
tf = isequal(t1,t2)
tf =

  logical

   1

Add 8 months to the date, and compare the datetime values for equality.

t1 = datetime(2013,9,13,0,0,0,'TimeZone','America/Anchorage');
t2 = datetime(2013,9,13,11,0,0,'TimeZone','Africa/Cairo');
tf = isequal(t1,t2)
tf =

  logical

   0

The datetime values are no longer equal since Cairo does not observe daylight saving time.

Input Arguments

collapse all

Inputs to be compared, specified as numeric arrays, categorical arrays, cell arrays, string arrays, tables, structures, 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 any combination of datetime arrays and cell arrays of character vectors for equality.

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 isequal 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 with dynamic properties – isequal returns logical 0 (false). This applies even if the properties have the same name and value.

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

  • You can compare any combination of datetime arrays and cell arrays of character vectors for equality.

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 isequal 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 with dynamic properties – isequal returns logical 0 (false). This applies even if the properties have the same name and value.

More About

collapse all

Tips

  • When comparing handle objects, use == to test whether objects have the same handle. Use isequal to determine if objects with different handles have equal property values.

  • Use isequaln if you want to test for equality and treat NaN, NaT, or <missing> values as equal.

  • The equality of two function handles depends on how they are constructed. For more information, see Compare Function Handles.

See Also

| | | |

Introduced before R2006a

Was this topic helpful?