How can I use any () in a multidimensional array?

I am testing an arbitrarily large, arbitrarily given array of logic elements, and I would like to know if any of them are true. any()only works on one dimension at a time, like sum(). I know that I can check the number of measurements and repeat any()until I get one answer, but I would like a faster and more frankly more elegant approach.

Ideas?

I am launching 2009a (R17, in the old language, I think).

+3
source share
2 answers

If your data is in matrix A , try the following:

anyAreTrue = any(A(:));

EDIT: , , A (:) , A, , - ( numel (A) -by- 1). ANY.

+10

, . . ,

( (:))

, true, numel (A) .

( (, [], 1))

reshape. , , - . , , :

======================

= myany (A)

% ,

result = any (A (:));

======================

m . MATLAB ( ) - . - , , , . , .

+2

Source: https://habr.com/ru/post/1705790/


All Articles