Documentation

uint8

8-bit unsigned integer arrays

Description

Variables in MATLAB®dat的a type (class)uint8are stored as 1-byte (8-bit) unsigned integers. For example:

y = uint8(10); whosy
Name Size Bytes Class Attributes y 1x1 1 uint8

For more information on integer types, seeIntegers.

Creation

Some array creation functions allow you to specify the data type. For instance,zeros(100,'uint8')creates a 100-by-100 matrix of zeros of typeuint8.

If you have an array of a different type, such asdoubleorsingle, then you can convert that array to an array of typeuint8by using theuint8function.

Syntax

Y = uint8(X)

Description

example

Y = uint8(X)converts the values inXto typeuint8. Values outside the range [0,28-1] map to the nearest endpoint.

Input Arguments

expand all

Input array, specified as a scalar, vector, matrix, or multidimensional array.

Data Types:double|single|int8|int16|int32|int64|uint16|uint32|uint64|logical|char

Examples

expand all

Convert a double-precision variable to an 8-bit unsigned integer.

x = 100;xtype类(x) =
xtype = 'double'
y = uint8(x)
y =uint8100

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

Introduced before R2006a

Was this topic helpful?