Array – How to use any () on a multidimensional array?

I’m testing an arbitrarily large, arbitrarily sized logical array, and I want to know if one or more of them are true. any() can only be in one dimension at a time Works, so does sum(). I know I can test the number of dimensions and repeat any () until I get an answer, but I want a faster, more frank, and more elegant method.

Ideas?

I am running 2009a (R17, in old terms, I think).

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

anyAreTrue = any(A(:));

Edit: To explain people who are not familiar with the syntax, A(:) uses the colon operator to get the entire contents of the array A, regardless of the size, and reshape them into a single column vector (size numberl) (A)×1). The operation on the result column vector only needs to call ANY once.

I am testing an arbitrarily large and arbitrarily sized logical array, and I want to know if there is one of them or Multiple is true. any() can only work in one dimension at a time, so does sum(). I know I can test the number of dimensions and repeat any() until I get an answer, but I want one more Faster, more frank, and more elegant method.

Ideas?

I am running 2009a (R17, in the old parlance, I think).

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

anyAreTrue = any(A(:));

Edit: To explain people who are not familiar with the grammar, A (:) Use the colon operator to get the entire contents of the array A, regardless of the size, and reshape them into a single column vector (size numberl) (A)×1). The operation on the result column vector only needs to call ANY once.

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 5289 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.