
上QQ阅读APP看本书,新人免费读10天
设备和账号都新为新人
2.3.2 关系运算符
MATLAB中的关系运算符有6个,具体可参见表2-6。
关系运算符可以用来对两个数值、两个数组、两个矩阵或两个字符串等数据类型进行比较,也可以进行不同数据类型的两个数据之间的比较,比较的方式根据所比较的两个数据类型的不同而不同。例如,在对矩阵和一个标量进行比较时,需要将矩阵中的每个元素与标量进行比较。
关系运算符通过比较对应的元素产生一个仅包含1和0的数值或矩阵,其元素代表的意义如下。
● 返回值为1,比较结果为真。
● 返回值为0,比较结果为假。
例2-52:关系运算符的运用。
在命令行窗口中输入:

输出结果:

在命令行窗口中输入:

输出结果:


在命令行窗口中输入:

输出结果:

例2-53:关系运算符的运算。
在命令行窗口中输入:

输出结果:

○ 提示
例2-53利用特殊的MATLAB数eps代替一个数组中的零元素,eps近似为2.2e-16。这种特殊的表达式在避免0作为分母时是很有用的。