The indicated statement most likely will result in unexpected behavior. This
is because the statements A && B
and A ||
B
always either return a logical value or throw an error.
Rewrite the code to perform the logical operation outside of the specified function.
For example, to determine whether the scalars a and b are both nonzero:
a = 1;
b = 2;
a && b
To determine if the arrays A
and B
each
have at least one nonzero element:
A = [1 2 3];
B = [0 0 0];
any(A & B)
To determine whether any of the elements in array A
and
array B
are nonzero:
A = [1 2 3];
B = [0 0 0];
any(A) && any(B)
To determine whether any of the elements in the array A
are
nonzero, and then determine the logical AND of the result and
B
:
A = [1 2 3];
B = [0 0 0];
any(A) && B