Main Content

是平等的

确定阵列平等

Description

例子

tf = is equal(一个,,,,b返回逻辑1((true) 如果一个andb等效;否则,它返回逻辑0((错误的)。See the输入参数针对每种数据类型的等价定义的部分。((Not a Number),纳特((Not a Time), undefined categorical elements, and值被认为是不等到其他元素以及他们自己。

治疗,,,,纳特,,,,,,,,andvalues as equal to other such values, useiSequaln

例子

tf = is equal(一个1,,,,一个2,...,An返回逻辑1((true)如果所有输入都是等效的。

Examples

collapse all

创建两个数字矩阵并进行比较以保持平等。

a =零(3,3)+1e-20;b =零(3,3);tf = is equal(a,b)
tf =逻辑0

The function returns logical0((错误的) 因为the matrices differ by a very small amount and are notexactly等式ual.

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

一个= struct('field1',0.005,'field2',,,,2500); B = struct('field2',,,,2500,'field1',0.005);

比较平等的结构。

tf = is equal(a,b)
tf =逻辑1

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

比较逻辑值trueto the double integer1

quequal(true,1)
ans =逻辑1

注意是平等的测试平等时,不考虑数据类型。

同样,比较'一个'to the ASCII-equivalent integer,65

是平等的('一个',,,,65)
ans =逻辑1

结果是合乎逻辑的1((true) 自从double('a')等式uals65

创建包含NAN值的三个向量。

a1 = [1 nan nan];a2 = [1 nan nan];a3 = [1 nan nan];

Compare the vectors for equality.

tf = is equal(一个1,,,,一个2,A3)
tf =逻辑0

结果是合乎逻辑的0((错误的) 因为是平等的does not treat NaN values as equal to each other.

确定2013年1月13日在阿拉斯加安克雷奇的午夜等于开罗的同一日期。

t1 = datetime(2013,1,13,0,0,0,'时区',,,,'America/Anchorage');t2 = datetime(2013,1,13,11,0,0,'时区',,,,'Africa/Cairo');tf = is equal(t1,t2)
tf =逻辑1

一个dd 8 months to the date, and compare the datetime values for equality.

T1 = DateTime(2013,9,13,0,0,0,'时区',,,,'America/Anchorage');T2 = DateTime(2013,9,13,11,0,0,'时区',,,,'Africa/Cairo');tf = is equal(t1,t2)
tf =逻辑0

DateTime值不再相等,因为开罗没有观察到日光节省时间。

即使大小和数据类型不同,是平等的返回逻辑1((true)when comparing a character vector and string scalar that contain the same sequence of characters.

是平等的("foo",,,,'foo'
ans =逻辑1

输入参数

collapse all

Inputs to be compared, specified as arrays.

In some cases, the types of the inputs do not have to match:

  • 如果数字输入的大小相同,并且其内容具有相等的值,则它们是等效的。该测试分别比较了数字阵列的真实和虚构部分。

  • 表,时间表,结构和单元阵列仅在所有元素和属性相等时才是等效的。

  • 包含相同字符序列的字符串标量和字符矢量是等效的。

Some data type comparisons have special considerations involving metadata. If the inputs areall

  • 结构 - 只要内容物相等,字段就不必按相同的顺序。

  • 顺序分类阵列 - 必须具有相同的类别集,包括其订单。

  • Categorical arrays that are not ordinal — Can have different sets of categories, and是平等的比较每对元素的类别名称。

  • Datetime arrays —是平等的比较时间点时忽略显示格式。如果阵列全部与时区关联,则是平等的比较时间而不是时钟时间(例如,01-May-2018 09:00:00 EDT01-May-2018 06:00:00 PDT, 所以是平等的返回true即使时钟时间为9:00和6:00)。

  • Objects —是平等的返回逻辑1((true)对于具有平等属性值的同一类的对象。

要比较的一系列输入,指定为阵列。

In some cases, the types of the inputs do not have to match:

  • 如果数字输入的大小相同,并且其内容具有相等的值,则它们是等效的。该测试分别比较了数字阵列的真实和虚构部分。

  • 表,时间表,结构和单元阵列仅在所有元素和属性相等时才是等效的。

  • 包含相同字符序列的字符串标量和字符矢量是等效的。

Some data type comparisons have special considerations involving metadata. If the inputs areall

  • 结构 - 只要内容物相等,字段就不必按相同的顺序。

  • 顺序分类阵列 - 必须具有相同的类别集,包括其订单。

  • Categorical arrays that are not ordinal — Can have different sets of categories, and是平等的比较每对元素的类别名称。

  • Datetime arrays —是平等的比较时间点时忽略显示格式。如果阵列全部与时区关联,则是平等的比较时间而不是时钟时间(例如,01-May-2018 09:00:00 EDT01-May-2018 06:00:00 PDT, 所以是平等的返回true即使时钟时间为9:00和6:00)。

  • Objects —是平等的返回逻辑1((true)对于具有平等属性值的同一类的对象。

Tips

  • The equality of two function handles depends on how they are constructed. For more information, see比较功能句柄

  • 是平等的返回逻辑0((错误的)对于具有动态属性的两个对象,即使属性具有相同的名称和值。

  • 是平等的在测试两个对象以保持平等时,仅比较存储的(非依赖性)属性。

  • When comparing two handle objects, use==测试对象是否具有相同的句柄。利用是平等的确定两个具有不同手柄的对象是否具有相等的属性值。

扩展功能

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

GPU代码生成
Generate CUDA® code for NVIDIA® GPUs using GPU Coder™.

版本历史记录

Introduced before R2006a