[英]Matlab & and < operator
In this expression 在这个表达中
lmin=lminflag & ~kmod & actminsub<nsm*pminu & actminsub>pminu;
is the & operator like a bitwise AND operator? 和运算符是按位AND运算符吗? lminflag and kmod are both arrays with either logical 1 or 0 as elements and lmin turns out to be either 1 or 0 as well. lminflag和kmod都是以逻辑1或0为元素的数组,而lmin也为1或0。
Yes. 是。
&
is a per-element AND operator. &
是每个元素的AND运算符。 &&
is a scalar AND operator, with conditional execution of the remainder of the statement. &&
是一个标量AND运算符,有条件地执行语句的其余部分。 For example, given: 例如,给定:
a = true;
b = false;
aa = [true false];
bb = [true true];
fnA = @()rand>0.5; %An anonymous function returning true half the time
Then: 然后:
a & b; %returns false
a && b; %returns false (same as above)
However 然而
aa & bb; %this an error
aa && bb; %returns the array [true false]
It's more interesting when the operands are functions, with side effects. 当操作数是具有副作用的函数时,会更有趣。
b & fnA; %Returns false, and the `rand` function is called (including a small performance hit, and an update to the random state)
b && fnA; %Returns false, and the `rand` function was not called (since `b` is false, the actual value of `fnA` doesn;t effect the result
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.