A comparison operator is applied to a function that returns logical values
(true
or false
). In this case, the
comparison always returns false
. Therefore, it is performed
incorrectly.
If you want to perform a comparison, rewrite your code by placing the operator
inside the function call. This example shows how to fix the code to determine
whether any element in a vector A
is greater than
1
.
Original | Revised | |
---|---|---|
A = [6 3 7 5];
|
A = [6 3 7 5];
|
In the original code, B
evaluates to
false
regardless of the value of A
,
because the any
function can return only logical
0
or 1
values. The revised code
correctly determines whether any element in A
is greater than
1
.