Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Test if any element of a vector equals 1

Tags:

matlab

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

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
like image 477
user2840470 Avatar asked Jan 31 '26 15:01

user2840470


1 Answers

I think you're looking for the any function:

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

You could achieve something like this using find, I wouldn't recommend it though. Here is one option:

if(numel(find(X(:,2) == 1)) > 0)
like image 50
Dan Avatar answered Feb 03 '26 05:02

Dan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!