FreeMat

- Main Page
- Related Pages

TYPEOF Determine the Type of an Argument

Section: Inspection Functions

# 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

- `'cell'` for cell-arrays
- `'struct'` for structure-arrays
- `'logical'` for logical arrays
- `'uint8'` for unsigned 8-bit integers
- `'int8'` for signed 8-bit integers
- `'uint16'` for unsigned 16-bit integers
- `'int16'` for signed 16-bit integers
- `'uint32'` for unsigned 32-bit integers
- `'int32'` for signed 32-bit integers
- `'float'` for 32-bit floating point numbers
- `'double'` for 64-bit floating point numbers
- `'string'` for string arrays

# 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 =
    cell

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

    --> typeof(struct('foo',3))

    ans =
    struct

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

    --> typeof(3>5)

    ans =
    logical

For the integers, the typecast operations are used to generate the arguments.

    --> typeof(uint8(3))

    ans =
    uint8
    --> typeof(int8(8))

    ans =
    int8
    --> typeof(uint16(3))

    ans =
    uint16
    --> typeof(int16(8))

    ans =
    int16
    --> typeof(uint32(3))

    ans =
    uint32
    --> typeof(int32(3))

    ans =
    int32
    --> typeof(uint64(3))

    ans =
    uint64
    --> typeof(int64(3))

    ans =
    int64

Float, and double can be created using the suffixes.

    --> typeof(1.0f)

    ans =
    single
    --> typeof(1.0D)

    ans =
    double
    --> typeof(1.0f+i)

    ans =
    single
    --> typeof(1.0D+2.0D*i)

    ans =
    double