What is the "MATLAB-way" to check if a vector only contains zeros, so that it will be evaluated to a scalar rather than to a vector. If I run this code:
vector = zeros(1,10)
%the "1" represents a function that returns a scalar
if 1 && vector == 0 %this comparision won't work
'success'
end
I get the error:
??? Operands to the || and && operators must be convertible to logical scalar values.
Use all
:
vector = zeros(1,10)
if 1 && all(vector == 0) %this comparision will work
'success'
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With