isfinite
Marks elements that are neither infinite nor NaN.
Category: Language Fundamentals > Data Types
Syntax
tf = isfinite(A)
Returns a logical array that is true where the element is a finite number.
Description
An element is finite when it is not Inf, -Inf or NaN. For a complex number both the real and imaginary parts must be finite. Integer types are always finite, so the result is all true.
isfinite(A) is equivalent to ~isinf(A) & ~isnan(A).
Input arguments
A- Numeric, logical or char array, or a datetime or duration array.
Output arguments
tf- Logical array the same size as
A.
Example
Filtering out bad values
x = [1 Inf -Inf NaN 4];
isfinite(x)
x(isfinite(x))
Output
ans = 1×5 logical array
1 0 0 0 1
ans = 1×2
1 4