This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.


Cast variable to different data type


B = cast(A,newclass)
B = cast(A,'like',p)


B = cast(A,newclass) converts A to class newclass, where newclass is the name of a built-in data type compatible with A. The cast function truncates any values in A that are too large to map into newclass.

B = cast(A,'like',p) converts A to the same data type and sparsity as the variable p. If A and p are both real, then B is also real. Otherwise, B is complex.


collapse all

Convert an int8 value to uint8.

Define a scalar 8-bit integer.

a = int8(5);

Convert a to an unsigned 8-bit integer.

b = cast(a,'uint8');
ans = 

Extended Capabilities

Introduced before R2006a