Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

int32

Convert to 32-bit signed integer

Syntax

intArray = int32(array)

Description

intArray = int32(array) converts the elements of an array into signed 32-bit (4-byte) integers of class int32.

Input Arguments

array

Array of any numeric class, such as single or double. If array is already of class int32, the int32 function has no effect.

Output Arguments

intArray

Array of class int32. Values range from –231 to 231 – 1.

The int32 function maps any values in array that are outside the limit to the nearest endpoint. For example,

int32(2^31)   % 2^31 = 2147483648

returns

ans =
    2147483647

Examples

Convert a double array to int32:

mydata = int32(magic(1000));

Related Examples

Alternatives

When preallocating integer arrays, specify the class in the call to functions that support a class name input (such as zeros, ones or eye), rather than calling an integer conversion function. For example,

I = int32(zeros(100));     % Creates an intermediate array

is not as efficient as

I = zeros(100, 'int32');   % Preferred 

More About

collapse all

Tall Array Support

This function fully supports tall arrays. For more information, see Tall Arrays.

Introduced before R2006a

Was this topic helpful?