isequal
Determine array equality
Description
tf = isequal(
returns logicalA,B
)1
(true
) ifA
andB
are equivalent; otherwise, it returns logical0
(false
). See theInput Argumentssection for a definition of equivalence for each data type.NaN
(Not a Number),NaT
(Not a Time), undefined categorical elements, and
values are considered to beunequalto other elements, as well as themselves.
To treatNaN
,NaT
,
, and
values as equal to other such values, useisequaln
.
tf = isequal(
returns logicalA1,A2,...,An
)1
(true
如果所有的输入都是武器装备valent.
Examples
Compare Two Numeric Matrices
Create two numeric matrices and compare them for equality.
A = zeros(3,3)+1e-20; B = zeros(3,3); tf = isequal(A,B)
tf =logical0
The function returns logical0
(false
) because the matrices differ by a very small amount and are notexactlyequal.
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 = isequal(A,B)
tf =logical1
Even though the ordering of the fields in each structure is different,isequal
treats them as the same because the values are equal.
Comparing Numeric Values with Special Nonnumeric Values
Compare the logical valuetrue
to the double integer1
.
isequal(true,1)
ans =logical1
Notice thatisequal
does not consider data type when it tests for equality.
Similarly, compare'A'
to the ASCII-equivalent integer,65
.
isequal('A',65)
ans =logical1
The result is logical1
(true
) sincedouble('A')
equals65
.
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 = isequal(A1,A2,A3)
tf =logical0
The result is logical0
(false
) becauseisequal
does not treat NaN values as equal to each other.
Compare Two Datetime Values
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 =logical1
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 =logical0
The datetime values are no longer equal since Cairo does not observe daylight saving time.
Compare Character Vector to String Scalar
Even though the sizes and data types are different,isequal
returns logical1
(true
) when comparing a character vector and string scalar that contain the same sequence of characters.
isequal("foo",'foo')
ans =logical1
Input Arguments
A,B
—Inputs to be compared (as separate arguments)
arrays
Inputs to be compared, specified as arrays.
In some cases, the types of the inputs do not have to match:
Numeric inputs are equivalent if they are the same size and their contents are of equal value. The test compares real and imaginary parts of numeric arrays separately.
Tables, timetables, structures, and cell arrays are equivalent only when all elements and properties are equal.
String scalars and character vectors containing the same sequence of characters are equivalent.
Some data type comparisons have special considerations involving metadata. If the inputs areall:
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 display format when it compares points in time. If the arrays are all associated with time zones, thenisequal
compares the instants in time rather than the clockface times (for example,01-May-2018 09:00:00 EDT
is the same instant as01-May-2018 06:00:00 PDT
, soisequal
returnstrue
even though the clockface times of 9:00 and 6:00 differ).Objects —
isequal
returns logical1
(true
) for objects of the same class with equal property values.
A1,A2,...,An
—Series of inputs to be compared (as separate arguments)
arrays
Series of inputs to be compared, specified as arrays.
In some cases, the types of the inputs do not have to match:
Numeric inputs are equivalent if they are the same size and their contents are of equal value. The test compares real and imaginary parts of numeric arrays separately.
Tables, timetables, structures, and cell arrays are equivalent only when all elements and properties are equal.
String scalars and character vectors containing the same sequence of characters are equivalent.
Some data type comparisons have special considerations involving metadata. If the inputs areall:
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 display format when it compares points in time. If the arrays are all associated with time zones, thenisequal
compares the instants in time rather than the clockface times (for example,01-May-2018 09:00:00 EDT
is the same instant as01-May-2018 06:00:00 PDT
, soisequal
returnstrue
even though the clockface times of 9:00 and 6:00 differ).Objects —
isequal
returns logical1
(true
) for objects of the same class with equal property values.
Tips
The equality of two function handles depends on how they are constructed. For more information, seeCompare Function Handles.
isequal
returns logical0
(false
) for two objects with dynamic properties, even if the properties have the same names and values.isequal
compares only stored (non-dependent) properties when testing two objects for equality.When comparing two handle objects, use
==
to test whether objects have the same handle. Useisequal
to determine if two objects with different handles have equal property values.
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
GPU Code Generation
Generate CUDA® code for NVIDIA® GPUs using GPU Coder™.
Thread-Based Environment
Run code in the background using MATLAB®backgroundPool
or accelerate code with Parallel Computing Toolbox™ThreadPool
.
This function fully supports thread-based environments. For more information, seeRun MATLAB Functions in Thread-Based Environment.
GPU Arrays
Accelerate code by running on a graphics processing unit (GPU) using Parallel Computing Toolbox™.
This function fully supports GPU arrays. For more information, seeRun MATLAB Functions on a GPU(Parallel Computing Toolbox).
Distributed Arrays
Partition large arrays across the combined memory of your cluster using Parallel Computing Toolbox™.
This function fully supports distributed arrays. For more information, seeRun MATLAB Functions with Distributed Arrays(Parallel Computing Toolbox).
Version History
Abrir ejemplo
Tiene una versión modificada de este ejemplo. ¿Desea abrir este ejemplo con sus modificaciones?
Comando de MATLAB
Ha hecho clic en un enlace que corresponde a este comando de MATLAB:
Ejecute el comando introduciéndolo en la ventana de comandos de MATLAB. Los navegadores web no admiten comandos de MATLAB.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select:.
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina(Español)
- Canada(English)
- United States(English)
Europe
- Belgium(English)
- Denmark(English)
- Deutschland(Deutsch)
- España(Español)
- Finland(English)
- France(Français)
- Ireland(English)
- Italia(Italiano)
- Luxembourg(English)
- Netherlands(English)
- Norway(English)
- Österreich(Deutsch)
- Portugal(English)
- Sweden(English)
- Switzerland
- United Kingdom(English)