Check if any element of the vector is 1

I am trying to use the find statement in Matlab as a boolean and Im wondering if its even possible, if so how?

This is what I am trying to do

//If The second column in X contains a 1, do something
if(find(X(:,2) == 1) == true)
//do something

      

+3


source to share


1 answer


I think you are looking for a function any

:

if(any(X(:,2) == 1))
//do something

      



You could achieve something similar using find

, but I would not recommend it. Here's one of the options:

if(numel(find(X(:,2) == 1)) > 0)

      

+4


source







All Articles