next up previous contents
Next: Array Generation and Manipulations Up: Type Cast Functions Previous: DCOMPLEX Convert to 32-bit   Contents

Subsections

TYPEOF Determine the Type of an Argument

Usage

Returns a string describing the type of an array. The syntax for its use is

   y = typeof(x),

The returned string is one of

Example

The following piece of code demonstrates the output of the typeof command for each possible type. The first example is with a simple cell array.

--> typeof({1})
ans = 
  <string>  - size: [1 4]
 cell

The next example uses the struct constructor to make a simple scalar struct.

--> typeof(struct('foo',3))
ans = 
  <string>  - size: [1 6]
 struct

The next example uses a comparison between two scalar integers to generate a scalar logical type.

--> typeof(3>5)
ans = 
  <string>  - size: [1 7]
 logical

For the smaller integers, and the 32-bit unsigned integer types, the typecast operations are used to generate the arguments.

--> typeof(uint8(3))
ans = 
  <string>  - size: [1 5]
 uint8
--> typeof(int8(8))
ans = 
  <string>  - size: [1 4]
 int8
--> typeof(uint16(3))
ans = 
  <string>  - size: [1 6]
 uint16
--> typeof(int16(8))
ans = 
  <string>  - size: [1 5]
 int16
--> typeof(uint32(3))
ans = 
  <string>  - size: [1 6]
 uint32

The 32-bit signed integer type is the default for integer arguments.

--> typeof(-3)
ans = 
  <string>  - size: [1 5]
 int32
--> typeof(8)
ans = 
  <string>  - size: [1 5]
 int32

Float, double, complex and double-precision complex types can be created using the suffixes.

--> typeof(1.0f)
ans = 
  <string>  - size: [1 5]
 float
--> typeof(1.0D)
ans = 
  <string>  - size: [1 6]
 double
--> typeof(1.0f+i)
ans = 
  <string>  - size: [1 7]
 complex
--> typeof(1.0D+2.0D*i)
ans = 
  <string>  - size: [1 8]
 dcomplex


next up previous contents
Next: Array Generation and Manipulations Up: Type Cast Functions Previous: DCOMPLEX Convert to 32-bit   Contents
Samit K. Basu 2005-03-16