文档

等式,,,,==

确定平等

Description

例子

一种==b返回带有元素设置为逻辑的逻辑数组1((true)阵列一种andb相等;否则,该元素是合乎逻辑的0((错误的)。该测试比较了数字阵列的真实和虚构部分。等式返回逻辑0((错误的) 在哪里一种orbhave NaN or undefined categorical elements.

等式((一种,,,,bis an alternative way to executea == b,但很少使用。它使运营商的载荷超载。

Examples

collapse all

创建两个包含真实数字和虚构数字的向量,然后比较向量以保持平等。

a =[1+i 3 2 4+i]; B = [1 3+i 2 4+i]; A == B
ans =1x4 logical array0 0 1 1

等式function tests both real and imaginary parts for equality, and returns logical1((true)only where both parts are equal.

创建一个字符向量。

m='masterpiece';

测试使用特定角色的存在==

m =='e'
ans =1x11 logical array0 0 0 0 1 0 0 0 1 0 1

这value of logical1((true)indicates the presence of the character'e'

创建一个具有两个值的分类数组:“头”and'tails'

a =categorical({“头”“头”'tails';'tails'“头”'tails'})
a =2x3 categorical array头部头部尾巴头尾巴尾巴

Find all values in the“头”category.

a ==“头”
ans =2x3逻辑数组1 1 0 0 1 0

逻辑的价值1((true)indicates a value in the category.

比较行一种平等。

a(1,:) == a(2,:)
ans =1x3 logical array0 1 1

逻辑的价值1((true)indicates where the rows have equal category values.

many numbers expressed in decimal text cannot be represented exactly as binary floating numbers. This leads to small differences in results that the==操作员反映。

对十进制表示的数字执行一些减法操作,并将结果存储在C

C = 0.5-0.4-0.1
C= -2.7756e-17

用十进制算术,Cshould be equal toexactly0。它的小价值是由于二进制浮点算术的性质。

CompareC0平等。

C== 0
ans =逻辑0

使用公差比较浮点数,到l,,,,instead of using==

TOL = EPS(0.5);ABS(C-0)
                   
ans =逻辑1

这two numbers,Cand0,彼此接近两个连续的浮点数0。5。在许多情况下Cmay act like0

Compare the elements of twodatetime数组。

Create twodatetimearrays in different time zones.

t1 = [2014,04,14,9,0,0; ​​2014,04,14,10,0,0];a = datetime(t1,'时区',,,,'America/Los_Angeles');一种。Format ='d-MMM-y HH:mm:ss Z'
a =2x1 datetime array14-APR-2014 09:00:00 -0700 14-APR-2014 10:00:00 -0700
t2 = [2014,04,14,12,0,0;2014,04,14,12,30,0]; B = datetime(t2,'时区',,,,'America/New_York');B.Format ='d-MMM-y HH:mm:ss Z'
b=2x1 datetime array14-APR-2014 12:00:00 -0400 14-APR-2014 12:30:00 -0400

Check where elements in一种andbare equal.

a == b
ans =2x1 logical array1 0

Input Arguments

collapse all

操作数,指定为标量,向量,矩阵或多维阵列。数字或字符串输入一种andb必须是相同的大小或具有兼容的尺寸(例如,一种is anm-by-nmatrix andbis a scalar or1-by-nrow vector). For more information, seeCompatible Array Sizes for Basic Operations

You can compare numeric inputs of any type, and the comparison does not suffer loss of precision due to type conversion.

If一种andbare categorical, datetime, or duration arrays, then they must be the same size unless one is a scalar.

  • 如果一个输入是一个分类数组,则另一个输入可以是分类数组,字符向量的单元格数组或单个字符向量。单个字符向量扩展到与其他输入相同大小的字符矢量的单元格数组中。如果两个输入都是序数分类数组,则它们必须具有相同的类别集,包括其订单。如果两个输入都是非序数的分类数组,则它们可以具有不同的类别集。看比较分类阵列元素for more details.

  • If one input is a datetime array, the other input can be a datetime array, a character vector, or a cell array of character vectors.

  • If one input is a duration array, the other input can be a duration array or a numeric array. The operator treats each numeric value as a number of standard 24-hour days.

  • 如果一个输入是字符串数组,则另一个输入可以是字符串数组,字符向量或字符向量的单元格数组。相应的元素一种andbare compared lexicographically.

数据类型:单身的|double|int8|int16|int32|int64|UINT8|uint16|UINT32|Uint64|逻辑|char|细绳|categorical|datetime|期间
复杂的数字支持:金宝app是的

Tips

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

Compatibility Considerations

expand all

R2016b中的行为发生了变化

扩展功能

Introduced before R2006a