Hi, How can I use short circuit operators(&&) in vector variable?
Best Answer
You cannot. && can only be used for scalars.
Note that if you are trying to code something like
if vector1 && vector2
then the "if" would be considered true only ifall values in "vector1 && vector2" evaluated to true, because that is how "if" behaves on vectors and matrices, as if there was an all() wrapped around everything:
if all(vector1 && vector2)
With some minor thought on the meaning of "&" you can see this would be the same as
But I do not assume that this helps, because you still process more elements than needed. You need a Mex function for short-cutting. For full arrays you find in the FEX:anyExceed andanyEq. But substantial modifications are required for accessing sparse arrays.
Best Answer