警告:为运算符 & 执行的 Matlab 式短路操作

warning: Matlab-style short-circuit operation performed for operator &

代码:

if (round(xw(1))>2) & (round(xw(2))>2) & (round(xw(1))<h-1) & (round(xw(2))<w-1)
        W0 = img(round(xw(1))-2:round(xw(1))+2,round(xw(2))-2:round(xw(2))+2);
else
        NA=1;
        break
endif

xw 是一个包含点坐标的列向量。 hw 是图像的尺寸。

我在 OCTAVE

中使用这些代码行

但是当我 运行 包含这些行的函数时,我收到警告

warning: Matlab-style short-circuit operation performed for operator &

是否尽管使用了&octave却在执行&&操作?

我了解到,如果我使用 &&,则根据第一个语句是 TrueFalse,对下一个语句进行评估。

那么,这是我收到此警告时发生的情况吗?那么这个问题的解决方案是什么?

我想检查是否所有语句都是 True 而不仅仅是第一个。

您可以改用 && 运算符来安全地避免警告。

警告来自以下事实:Matlab has a special handling for & operators in this context:

When you use the element-wise & and | operators in the context of an if or while loop expression (and only in that context), they use short-circuiting to evaluate expressions.

出于兼容性原因,Octave 会检测到此行为并模拟 Matlab 的操作。请注意,在 Matlab 中使用 && 也是完全安全的,因为无论如何都是隐式使用的。