等式,,,,==
确定平等
Description
Examples
两个向量的平等
创建两个包含真实数字和虚构数字的向量,然后比较向量以保持平等。
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'
。
Find Values in Categorical Array
创建一个具有两个值的分类数组:“头”
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
用十进制算术,C
should be equal toexactly0
。它的小价值是由于二进制浮点算术的性质。
CompareC
到0
平等。
C== 0
ans =逻辑0
使用公差比较浮点数,到l
,,,,instead of using==
。
TOL = EPS(0.5);ABS(C-0)
ans =逻辑1
这two numbers,C
and0
,彼此接近两个连续的浮点数0。5
。在许多情况下C
may act like0
。
比较DateTime值
Compare the elements of twodatetime
数组。
Create twodatetime
arrays 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一种
andb
are equal.
a == b
ans =2x1 logical array1 0
Input Arguments
一种
,,,,b
-操作数
scalars|vectors|matrices|multidimensional arrays
操作数,指定为标量,向量,矩阵或多维阵列。数字或字符串输入一种
andb
必须是相同的大小或具有兼容的尺寸(例如,一种
is anm
-by-n
matrix andb
is a scalar or1
-by-n
row 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一种
andb
are 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.
如果一个输入是字符串数组,则另一个输入可以是字符串数组,字符向量或字符向量的单元格数组。相应的元素
一种
andb
are compared lexicographically.
数据类型:单身的
|double
|int8
|int16
|int32
|int64
|UINT8
|uint16
|UINT32
|Uint64
|逻辑
|char
|细绳
|categorical
|datetime
|期间
复杂的数字支持:金宝app是的
Tips
When comparing handle objects, use
==
测试对象是否具有相同的句柄。采用是平等的
确定具有不同手柄的对象是否具有相等的属性值。
Compatibility Considerations
Implicit expansion change affects arguments for operators
R2016b中的行为发生了变化
从R2016B开始,随着添加隐式扩展,以前返回错误的基本操作的某些参数的组合现在产生结果。例如,您以前无法添加一行和列向量,但是这些操作数现在对添加有效。换句话说,表达[1 2] + [1;2]
以前返回了尺寸不匹配错误,但现在执行。
如果您的代码使用元素操作员,并依赖MATLAB的错误®先前返回的尺寸不匹配的大小,尤其是在try
/catch
block, then your code might no longer catch those errors.
For more information on the required input sizes for basic array operations, seeCompatible Array Sizes for Basic Operations。
扩展功能
高阵列
用比在内存中拟合更多的行的数组计算。
此功能完全支持高阵列。金宝app有关更多信息,请参阅高阵列。
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
Usage notes and limitations:
代码生成不支持使用金宝app
等式
到test equality between an enumeration member and a string array, a character array, or a cell array of character arrays.
GPU数组
一种ccelerate code by running on a graphics processing unit (GPU) using Parallel Computing Toolbox™.
This function fully supports GPU arrays. For more information, see在GPU上运行MATLAB功能(并行计算工具箱)。
分布式阵列
使用Parallel Computing Toolbox™,将群集组合内存的组合存储器划分。
This function fully supports distributed arrays. For more information, seeRun MATLAB Functions with Distributed Arrays(并行计算工具箱)。
也可以看看
Introduced before R2006a
Open Example
一种modified version of this example exists on your system. Do you want to open this version instead?
m一种TLAB Command
您单击了与此MATLAB命令相对应的链接:
运行该命令通过输入MATLAB逗号nd Window. Web browsers do not support MATLAB commands.
Select a Web Site
选择一个网站以获取可用的翻译内容,并查看本地事件和优惠。根据您的位置,我们建议您选择:。
You can also select a web site from the following list:
如何获得最佳网站性能
选择中国网站(中文或英语)以获得最佳场地性能。其他Mathworks乡村网站未针对您所在的访问进行优化。
一种mericas
- 一种mérica Latina((Español)
- Canada((English)
- United States((English)