CAST Typecast Variable to Specified Type

Section: Type Conversion Functions

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 = 

 3 


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

--> cast([1 0 3 0],'logical')

ans = 

 1 0 1 0 


inserted by FC2 system