Documentation

This is machine translation

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

uint8

Convert to 8-bit unsigned integer

Syntax

intArray = uint8(array)

Description

intArray = uint8(array) converts the elements of an array into unsigned 8-bit (1-byte) integers of class uint8.

Input Arguments

array

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

Output Arguments

intArray

Array of class uint8. Values range from 0 to 28 – 1.

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

uint8(2^8)   %  2^8 = 256

returns

ans =
    255

Examples

Convert a double array to uint8:

mydata = uint8(magic(10));

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

is not as efficient as

I = zeros(100, 'uint8');   % 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?