Skip to Main Content Skip to Search
Product Documentation

int16 - Convert to 16-bit signed integer

Syntax

intArray = int16(array)

Description

intArray = int16(array) converts the elements of an array into signed 16-bit (2-byte) integers of class int16.

Input Arguments

array

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

Output Arguments

intArray

Array of class int16. Values range from –215 to 215 – 1.

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

int16(2^15)   % 2^15 = 32768

returns

ans =
    32767

Examples

Convert a double array to int16:

mydata = int16(magic(100));

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 = int16(zeros(100));     % Creates an intermediate array

is not as efficient as

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

See Also

double | int32 | int64 | int8 | intmax | intmin | single | uint16 | uint32 | uint64 | uint8

Tutorials

  


Free MATLAB Interactive Kit

Explore how to use MATLAB to make advancements in engineering and science.


Download free kit

Trials Available

Try the latest version of MATLAB and other MathWorks products.


Get trial software
 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS