CAST Typecast Variable to Specified Type

Section: Array Generation and Manipulations

Usage

The cast function allows you to typecast a variable from one type to another. The syntax for its use is
    y = cast(x,toclass)

where toclass is the name of the class to cast x to. Note that the typecast must make sense, and that toclass must be one of the builtin types. The current list of supported types is

Example

Here is an example of a typecast from a float to an 8-bit integer
--> cast(pi,'uint8')
ans = 
  <uint8>  - size: [1 1]
 3  

and here we cast an array of arbitrary integers to a logical array

--> cast([1 0 3 0],'logical')
ans = 
  <logical>  - size: [1 4]
 
Columns 1 to 4
 1  0  1  0