Skip to content

cast

Convert an array to a different element type.

B = cast(A, newclass)

Returns A converted to the type named by newclass (a string like 'double', 'single', 'int32', 'uint8', 'logical', etc.). Equivalent to <newclass>(A) but lets the type name be a runtime string.

cast(3.7, 'int32') % 3 (truncated to int)
cls = 'single'; cast(pi, cls) % 3.14159 in single precision
  • double — Convert to double-precision floating-point.
  • single — Convert to single-precision floating-point.
  • int32 — Convert to signed 32-bit integer.