next up previous contents
Next: DOUBLE Convert to 64-bit Up: Type Cast Functions Previous: INT16 Convert to Signed   Contents

Subsections

INT32 Convert to Signed 32-bit Integer

Usage

Converts the argument to an signed 32-bit Integer. The syntax for its use is

   y = int32(x)

where x is an n-dimensional numerical array. Conversion follows the general C rules (e.g., if x is outside the normal range for a signed 32-bit integer of [-2147483648,2147483647], the least significant 32 bits of x are used after conversion to a signed integer). Note that both NaN and Inf both map to 0.

Example

The following piece of code demonstrates several uses of int32. First, the routine uses

--> int32(100)
ans = 
  <int32>  - size: [1 1]
           100  
--> int32(-100)
ans = 
  <int32>  - size: [1 1]
          -100

In the next example, an integer outside the range of the type is passed in. The result is the 32 least significant bits of the argument.

--> int32(40e9)
ans = 
  <int32>  - size: [1 1]
   -2147483648

In the next example, a positive double precision argument is passed in. The result is the signed integer that is closest to the argument.

--> int32(pi)
ans = 
  <int32>  - size: [1 1]
             3

In the next example, a complex argument is passed in. The result is the signed integer that is closest to the real part of the argument.

--> int32(5+2*i)
ans = 
  <int32>  - size: [1 1]
             5

In the next example, a string argument is passed in. The string argument is converted into an integer array corresponding to the ASCII values of each character.

--> int32('helo')
ans = 
  <int32>  - size: [1 4]
 
Columns 1 to 4
           104            101            108            111

In the last example, a cell-array is passed in. For cell-arrays and structure arrays, the result is an error.

--> int32({4})
Error: Cannot convert cell-arrays to any other type.

\begin{center}\vbox{\input{float}
}\end{center}


next up previous contents
Next: DOUBLE Convert to 64-bit Up: Type Cast Functions Previous: INT16 Convert to Signed   Contents
Samit K. Basu 2005-03-16