Main Content

isnumeric

Determine whether input is numeric array

Description

TF = isnumeric(A) returns logical 1 (true) if A is an array of numeric data type. Otherwise, it returns logical 0 (false).

Numeric types in MATLAB® include: int8, int16, int32, int64, uint8, uint16, uint32, uint64, single, and double. For more information, see Integer Classes and Floating-Point Numbers.

example

Examples

collapse all

Determine if a real number is a numeric type.

TF = isnumeric(2)
TF = logical
   1

MATLAB® stores numeric data as a double-precision format by default, which is a numeric type.

Now create a signed 16-bit integer type using int16. Check if it is a numeric type.

TF = isnumeric(int16(-256))
TF = logical
   1

Determine if an array containing infinity or not-a-number values is a numeric type.

Create several calculations that return Inf and assign the results to an array. Check if the array is a numeric type.

A = [1/0 log(0) 1e1000]
A = 1×3

   Inf  -Inf   Inf

TF = isnumeric(A)
TF = logical
   1

MATLAB represents infinity by the special value Inf as a double type.

Create several calculations that return NaN and assign the results to an array. Check if the array is a numeric type.

A = [0/0 -Inf/Inf]
A = 1×2

   NaN   NaN

TF = isnumeric(A)
TF = logical
   1

MATLAB represents not-a-number by the special value NaN, as a double type.

Determine if an array containing floating-point numbers is a numeric type.

A = [-3.5e2 2.5; single(3) pi]
A = 2x2 single matrix

 -350.0000    2.5000
    3.0000    3.1416

TF = isnumeric(A)
TF = logical
   1

Now create a cell array that contains the array A and other numbers. Use class to identify the type of the cell array. Check if it is a numeric type.

B = {A -4; 2 1}
B=2×2 cell array
    {2x2 single}    {[-4]}
    {[       2]}    {[ 1]}

type = class(B)
type = 
'cell'
TF = isnumeric(B)
TF = logical
   0

The cell array is not a numeric type since it is a cell type.

Input Arguments

collapse all

Input array, specified as a scalar, vector, matrix, or multidimensional array. MATLAB has the following numeric types.

Integer TypeDescription

single

single-precision floating-point

double

double-precision floating-point

int8

8-bit signed integer

int16

16-bit signed integer

int64

64-bit signed integer

int32

32-bit signed integer

uint8

8-bit unsigned integer

uint16

16-bit unsigned integer

uint32

32-bit unsigned integer

uint64

64-bit unsigned integer

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

GPU Code Generation
Generate CUDA® code for NVIDIA® GPUs using GPU Coder™.

HDL Code Generation
Generate VHDL, Verilog and SystemVerilog code for FPGA and ASIC designs using HDL Coder™.

Version History

Introduced before R2006a