Main Content

isinteger

Determine whether input is integer array

Description

example

TF= isinteger(A)returns logical1(true) ifAis an array of integer type. Otherwise, it returns logical0(false).

Integer types in MATLAB®包括:int8,int16,int32,int64,uint8,uint16,uint32, anduint64. For more information, seeInteger Classes.

Examples

collapse all

Determine if a real number is an integer type.

TF = isinteger(2)
TF =logical0

MATLAB® stores a real number as adoubletype by default.

Convert the number to a signed 8-bit integer type using theint8function. Check if it is an integer type.

TF = isinteger(int8(2))
TF =logical1

Determine if a complex number is an integer type.

A = 3.5 - 2.5i
A = 3.5000 - 2.5000i
TF = isinteger(A)
TF =logical0

MATLAB stores a complex number as adoubletype by default.

Convert the complex number into a signed 32-bit integer type using theint32function. Check if it is an integer type.

B =int32(A)
B =int324 - 3i
TF = isinteger(B)
TF =logical1

When a number with decimal digits is converted to an integer type, MATLAB rounds it to the nearest integer.

Determine if an array containing integer numbers is an integer type.

Create an array using theint8function. Check if it is an integer type.

A = [int8(1:5)]
A =1x5 int8 row vector1 2 3 4 5
TF = isinteger(A)
TF =logical1

现在,创建包含数组的单元数组Aand other integer numbers. Useclassto identify the type of the cell array. Check if it is an integer type.

b = {int8(-4);INT8(2)INT8(1)}
B=2×2 cell array{1x5 int8} {[-4]} {[ 2]} {[ 1]}
type = class(B)
type = 'cell'
TF = isinteger(B)
TF =logical0

The cell array is not an integer 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 integer types.

Integer Type Description

int8

8-bit signed integer

int16

16-bit signed integer

int64

64位符号整数

int32

32-bit signed integer

uint8

8位无符号整数

uint16

16-bit unsigned integer

uint32

32-bit unsigned integer

uint64

64-bit unsigned integer

Tips

  • For a floating-point number of asingle要么doubletype, you can check if it is also an integer by using the回合function (within the floating-point relative accuracyeps). If the rounded value of the number is equal to the original value before rounding, then the number is an integer. For example,2 ==圆(2)returns logical1(true) since2is an integer.

Extended Capabilities

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

GPU Code Generation
使用GPU Coder™为NVIDIA®GPU生成CUDA®代码。

Introduced before R2006a