Documentation Center

  • Trial Software
  • Product Updates

uint16

Convert to 16-bit unsigned integer

Syntax

intArray = uint16(array)

Description

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

Input Arguments

array

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

Output Arguments

intArray

Array of class uint16. Values range from 0 to 216 – 1.

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

uint16(2^16)   %  2^16 = 65536

returns

ans =
    65535

Examples

Convert a double array to uint16:

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

is not as efficient as

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

See Also

| | | | | | | | | |

Tutorials

Was this topic helpful?