Warning: Matlab style short circuit operation performed on & operator

code:

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

is a column vector that contains the coordinates of the point. h

and w

are the dimensions of the image.

I am using these lines of codes in OCTAVE

But when I run a function that contains these lines, I get a warning

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

This is despite the fact that &

, octave perform &&

the operation?

I found out that if I use &&

, then depending on the first operator True

or the False

following operators will be calculated.

So this is what happens when I get this warning? What is the solution to this problem?

I want to check if all the expressions True

, not just the first ones.

+3


source to share


1 answer


You can safely avoid the warning by using the operator instead &&

.

The warning comes from the fact that Matlab has special handling for operators &

in this context:



When you use element-wise and | statements in the context of if or while (and only in this context), they use short-circuiting to evaluate expressions.

For compatibility reasons, Octave detects this behavior and emulates what Matlab does. Note that it is completely safe to use &&

it in Matlab as well, as it is something that is implicitly used anyway.

+3


source







All Articles