Main Content

castFiToMATLAB

Cast fi object type to an equivalent built-in MATLAB data type

Since R2020a

Description

example

y = castFiToMATLAB(u) casts the input u to an equivalent MATLAB® built-in data type when possible.

If the input u is a fi object type that can be represented exactly by a built-in MATLAB data type, then the output is this built-in data type. If u is a fi object type that cannot be exactly represented by a built-in data type, or if it is already a built-in data type, then the output is the same as the input.

Examples

collapse all

Use the castFiToMATLAB function to cast fi objects to equivalent built-in MATLAB data types.

Create a signed fi variable with a 16-bit word length and zero fraction length. This is equivalent to an int16 data type. Cast the variable to the equivalent MATLAB data type using the castFiToMATLAB function.

u = fi(25,1,16,0);
y1 = castFiToMATLAB(u)
y1 =

  int16

   25

When the input is a fi object with a non-zero fraction length, the function returns the original fi object because the input cannot be represented by a built-in data type.

u = fi(pi,1,64,32);
y2 = castFiToMATLAB(u)
y2 = 

    3.1416

          DataTypeMode: Fixed-point: binary point scaling
            Signedness: Signed
            WordLength: 64
        FractionLength: 32

When the input is a double-precision fi object, the function returns a double with the same value.

T = numerictype('Double');
u = fi(25,T)
u = 

    25

          DataTypeMode: Double
y3 = castFiToMATLAB(u)
class(y3)
y3 =

    25

ans =

    'double'

Input Arguments

collapse all

Numeric input array, specified as a scalar, vector, matrix, or multidimensional array.

Data Types: double | single | half | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | fi
Complex Number Support: Yes

Output Arguments

collapse all

Numeric output, returned as a scalar, vector, matrix, or multidimensional array with the same value and dimensions as the input.

If the input u is a fi object that can be represented exactly by a built-in MATLAB data type, then the output is this built-in data type. If u is a fi object that cannot be exactly represented by a built-in data type, or if it is already a built-in data type, then the output is the same as the input.

Version History

Introduced in R2020a