all

Purpose

Test arrays for logical conditions.

Synopsis

Y = all(X)

Description

all(X), where X is a vector, returns 1 if all of the elements of X are nonzero. It returns 0 if any single element is zero. For matrices, all(X) operates on the columns of X, returning a row vector of 1s and 0s.

Examples

This function is particularly useful in if statements

if all(A < 0.5)
    do something
end
because an if wants to respond to a single condition, not a vector of possibly conflicting suggestions. Applying the function twice, as in all(all(A)), always reduces the matrix to a scalar condition.

See Also

&, |, ~, any

(c) Copyright 1994 by The MathWorks, Inc.