在此表达式中
lmin=lminflag & ~kmod & actminsub<nsm*pminu & actminsub>pminu;
是&amp;运算符像一个按位AND运算符? lminflag和kmod都是数组,逻辑1或0作为元素,lmin也是1或0。
答案 0 :(得分:5)
是。
&
是每个元素的AND运算符。 &&
是一个标量AND运算符,条件执行语句的其余部分。例如,给定:
a = true;
b = false;
aa = [true false];
bb = [true true];
fnA = @()rand>0.5; %An anonymous function returning true half the time
然后:
a & b; %returns false
a && b; %returns false (same as above)
然而
aa & bb; %this an error
aa && bb; %returns the array [true false]
当操作数是函数时,它更有趣,带有副作用。
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