allfinite

Tests whether all elements of an array are finite.

Category: Language Fundamentals > Data Types

Syntax

tf = allfinite(A)

Returns a single logical value: true when no element is Inf, -Inf or NaN.

Description

It is a compact check at the start of a function that cannot handle infinite or missing values: assert(allfinite(x)). Integer and logical arrays are always finite. An empty array gives true.

Input arguments

A
Numeric or logical array of any size. For complex data, both parts must be finite.

Output arguments

tf
Scalar logical.

Example

Finite or not

allfinite([1 2; 3 4])
allfinite([1 Inf])
allfinite([1 NaN])
Output
ans = logical
   1
ans = logical
   0
ans = logical
   0

See also

isfinite isinf isnan anynan all