23.12.2012 Views

MATLAB Function Reference Volume 1: A - E - Bad Request

MATLAB Function Reference Volume 1: A - E - Bad Request

MATLAB Function Reference Volume 1: A - E - Bad Request

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

2any<br />

Purpose Test for any nonzeros<br />

Syntax B = any(A)<br />

B = any(A,dim)<br />

Description B = any(A) tests whether any of the elements along various dimensions of an<br />

array are nonzero or logical true (1).<br />

If A is a vector, any(A) returns logical true (1) if any of the elements of A are<br />

nonzero, and returns logical false (0) if all the elements are zero.<br />

If A is a matrix, any(A) treats the columns of A as vectors, returning a row<br />

vector of 1s and 0s.<br />

If A is a multidimensional array, any(A) treats the values along the first<br />

non-singleton dimension as vectors, returning a logical condition for each<br />

vector.<br />

B = any(A,dim) tests along the dimension of A specified by scalar dim.<br />

1 0 1<br />

0 0 0<br />

Examples Given,<br />

A<br />

A = [0.53 0.67 0.01 0.38 0.07 0.42 0.69]<br />

then B = (A < 0.5) returns logical true (1) only where A is less than one half:<br />

0 0 1 1 1 1 0<br />

The any function reduces such a vector of logical conditions to a single<br />

condition. In this case, any(B) yields 1.<br />

This makes any particularly useful in if statements,<br />

if any(A < 0.5)<br />

do something<br />

end<br />

1 0 1<br />

any(A,1)<br />

1<br />

0<br />

any(A,2)<br />

any<br />

2-55

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!