typecast
- :
y =typecast(x, class)¶ Reinterpret the raw bytes of x as the type named by class, leaving the underlying bit pattern untouched.
No numeric conversion takes place: the in-memory bytes of x are copied verbatim and then viewed as elements of class, so the element count of y changes whenever the source and target types differ in width. For instance a scalar
doubleoccupies eight bytes and becomes a 1-by-2uint32array, while twouint32values become onedouble. In MATLAB mode x must be a full real numeric array and class one of the integer classes,single, ordouble. In the Octave dialect (dialect("octave"),--dialect octave, or a%#dialect: octaveheader) character arrays are also accepted as x, and"char"is accepted as class so bytes can be reinterpreted as a character array (nexus#12915); MATLAB mode refuses both directions, matching R2026a (char()/uint8()/native2unicode/unicode2nativeinstead). The total number of bytes in x must divide evenly into the size of the target element, otherwise an error is raised. The result is a row vector when x is a row and a column vector otherwise. Because it exposes the host byte order, the output oftypecastis platform dependent.