How do I use the boolean operator on a boolean array?

I looked through the documentation and SE properly but couldn't find a solution: given an arbitrarily large vector of booleans, how to return, for example. boolean AND setpoints?

I would expect something like:

and([1 1 1])  -->  1

      

(since it true && true && true

gives 1). This is of course invalid syntax.

My goal is to find the fastest way to compare two binary vectors of the same size and return 1 if they are identical and 0 if not. Since element-wise and

returns a vector if used on two vectors, hence the title of the question.

+3


source to share


1 answer


Use all()

:



result = all(a == b);

      

+7


source







All Articles