-10

我来到了这两个语句,在matlab这里想问一下语法的含义。

area_xy = (f > 1);

area_xyz = (f == 1);

这是否意味着例如area_xy包含某些 vecotr 的元素,f使得这些元素是> 1

谢谢。

4

1 回答 1

3

在 MATLAB 中,比较运算符(例如 , , >)总是给出一个布尔结果:为真,为假。此外,如果其中一个操作数是向量,或者两个操作数都是大小相同的向量,则按元素进行比较,结果是布尔结果的向量。例如:==<=10

x = (1 < 2)     % x contains 1 since this is true
x = (1 == 2)    % x contains 0 since this is false

a = [ 1 3 5 3 2 ]
x = (a < 3)         % x contains [ 1 0 0 0 1 ], since 1 and 2 are less than 3 but the others are not

a = [ 1 3 5 2 3 ]
b = [ 1 4 2 2 4 ]
x = (a == b)        % x contains [ 1 0 0 1 0 ], since elements 1 and 4 are the same in each

所以,area_xy不包含满足不等式的元素f;相反,它包含一个掩码,其中包含1不等式为真和不等式的0位置。您可以f通过评估获得满足此要求的实际值:

f(area_xy)
于 2013-02-25T15:24:07.643 回答