Convert to 32-bit signed integer
intArray = int32(array)
converts
the elements of an array into signed 32-bit (4-byte) integers of class intArray
= int32(array
)int32
.
|
Array of any numeric class, such as |
|
Array of class The int32(2^31) % 2^31 = 2147483648 returns ans = 2147483647 |
Convert a double
array to int32
:
mydata = int32(magic(1000));
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