Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check in MATLAB if a vector only contains zeros?

Tags:

matlab

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.

like image 479
Lucas Avatar asked May 20 '10 12:05

Lucas


1 Answers

Use all:

vector = zeros(1,10)
if 1 && all(vector == 0)   %this comparision will work
    'success'
end
like image 126
ptomato Avatar answered Sep 20 '22 07:09

ptomato