Main Content

Simulink.NumericType

Specify floating-point, integer, or fixed-point data type

Description

Use a Simulink.NumericType object to set and share numeric data types for signal, state, and parameter data in a model.

  1. Create an instance of this class in the MATLAB® base workspace, a model workspace, or a data dictionary. To create a numeric type in a model workspace, you must clear the Is alias property.

  2. Set the properties of the object to create a custom floating point, integer, or fixed point data type.

  3. Assign the data type to all signals and parameters of your model that you want to conform to the data type.

Assigning a data type in this way allows you to change the data types of the signals and parameters in your model by changing the properties of the object that describe them. You do not have to change the model itself.

To rename a data type in a model and in the code that you generate from a model (by generating a typedef statement), you can use a Simulink.AliasType object.

Creation

You can create a Simulink.NumericType object several ways.

  • Interactively create a Simulink.NumericType object using the Type Editor or Model Explorer.

  • Programmatically create a Simulink.NumericType object using the Simulink.NumericType function described here.

Description

example

typeObj = Simulink.NumericType returns a Simulink.NumericType object with default property values.

Properties

expand all

Bias for slope and bias scaling of a fixed-point data type (Fixed-Point Designer™), specified as a real number.

If you use a number with a data type other than double to set the value, Simulink® converts the value to double.

Example: 3

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical

Specification to generate or import the type definition (typedef) in the generated code (Simulink Coder™), specified as 'Auto', 'Exported, or 'Imported'.

The table shows the effect of each option.

ValueAction
'Auto' (default)If no value is specified for HeaderFile, export the type definition to model_types.h. model is the model name.

If a value is specified for HeaderFile, import the data type definition from the specified header file.
'Exported'Export the data type definition to a header file, which can be specified in the HeaderFile property. If no value is specified for HeaderFile, the header file name defaults to type.h. type is the data type name.
'Imported'Import the data type definition from a header file, which can be specified in the HeaderFile property. If no value is specified for HeaderFile, the header file name defaults to type.h. type is the data type name.

Set the data scope to Imported or Exported to avoid potential MISRA C:2012 violations.

For more information, see Control File Placement of Custom Data Types (Embedded Coder).

Mode of the numeric data type, specified as one of these character vectors:

  • 'Double' — Same as the MATLAB double type.

  • 'Single' — Same as the MATLAB single type.

  • 'Half' — Half-precision floating-point type.

  • 'Boolean' — Same as the MATLAB boolean type.

  • 'Fixed-point: unspecified scaling' — A fixed-point data type with unspecified scaling.

  • 'Fixed-point: binary point scaling' — A fixed-point data type with binary-point scaling.

  • 'Fixed-point: slope and bias scaling' — A fixed-point data type with slope and bias scaling.

Selecting a half-precision or fixed-point data type mode can, depending on the other dialog box options that you select, cause the model to run only on systems that have a Fixed-Point Designer license.

Data Types: char

Data type override mode, specified as 'Inherit' or 'Off'.

  • If you specify 'Inherit', the data type override setting for the context in which this numeric type is used (block, signal, Stateflow chart in Simulink) applies to this numeric type.

  • If you specify 'Off', data type override does not apply to this numeric type.

For more information about data type override, see Control Data Type Override.

Data Types: char

Custom description of the data type, specified as a character vector.

Example: 'This is a floating-point data type.'

Data Types: char

Exponent for binary point scaling, specified as a real number. Setting this property causes Simulink software to set the FractionLength and Slope properties accordingly, and vice versa. This property applies only if the DataTypeMode is Fixed-point: binary point scaling or Fixed-point: slope and bias scaling.

If you use a number with a data type other than double to set the value, Simulink converts the value to double.

This property must be set programmatically.

Example: -8

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical

Bit length of the fractional portion of a fixed-point number (Fixed-Point Designer), specified as a real integer. This property equals -FixedExponent. Setting this property causes Simulink software to set the FixedExponent property accordingly, and vice versa.

If you use a number with a data type other than double to set the value, Simulink converts the value to double.

Example: 8

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical

Name of the header file that contains the type definition (typedef) in the generated code, specified as a character vector.

If this property is specified, the specified name is used during code generation for importing or exporting. If this property is empty, the value defaults to type.h if DataScope equals 'Imported' or 'Exported', or defaults to model_types.h if DataScope equals 'Auto'.

By default, the generated #include directive uses the preprocessor delimiter " instead of < and >. To generate the directive #include <myTypes.h>, specify HeaderFile as '<myTypes.h>'.

For more information, see Control File Placement of Custom Data Types (Embedded Coder).

Example: 'myHdr.h'

Example: 'myHdr'

Example: 'myHdr.hpp'

Data Types: char

Specification to create a data type alias by using the name of the object, specified as true (yes) or false (no).

If you specify true, the object acts as a data type alias in a similar manner to a Simulink.AliasType object. For more information, see Manage Replacement of Simulink Data Types in Generated Code (Embedded Coder).

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical

Signedness of a fixed-point data type (Fixed-Point Designer), specified as 'Signed' (signed), 'Unsigned' (unsigned), or 'Auto' (inherit signedness).

Data Types: char

Signedness of a fixed-point data type (Fixed-Point Designer), specified as a Boolean.

Data Types: logical

Slope for slope and bias scaling of a fixed-point data type (Fixed-Point Designer), specified as a real number.

This property equals SlopeAdjustmentFactor * 2^FixedExponent. If SlopeAdjustmentFactor is 1.0, Simulink software displays the value of this field as 2^SlopeAdjustmentFactor. Otherwise, it displays it as a numeric value. Setting this property causes Simulink software to set the FixedExponent and SlopeAdjustmentFactor properties accordingly, and vice versa.

If you use a number with a data type other than double to set the value, Simulink converts the value to double.

This property appears only if DataTypeMode is Fixed-point: slope and bias scaling.

Example: 5.2

Example: 2^9

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical

Slope for slope and bias scaling of a fixed-point data type (Fixed-Point Designer), specified as a real number in the range [1, 2).

Setting this property causes Simulink software to adjust the Slope property accordingly, and vice versa. This property applies only if DataTypeMode is Fixed-point: slope and bias scaling.

If you use a number with a data type other than double to set the value, Simulink converts the value to double.

This property must be set programmatically.

Example: 1.7

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical

Word size of a fixed-point (Fixed-Point Designer) or integer data type, specified as an integer number of bits.

This property appears only if DataTypeMode is Fixed-point.

If you use a number with a data type other than double to set the value, Simulink converts the value to double.

Example: 8

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical

Object Functions

isbooleanDetermine whether numeric type represents the Boolean data type boolean
isdoubleDetermine whether numeric type represents the double-precision, floating-point data type double
isfixedDetermine whether numeric type represents a fixed-point data type
isfloatDetermine whether numeric type represents a floating-point data type
isscalingbinarypointDetermine whether fixed-point numeric type has binary-point scaling
isscalingslopebiasDetermine whether numeric type represents a fixed-point data type with slope-and-bias scaling
isscalingunspecifiedDetermine whether numeric type represents a data type with unspecified scaling
issingleDetermine whether numeric type represents the single-precision, floating-point data type single
ishalfDetermine whether numeric type represents the half-precision, floating-point data type half

Examples

collapse all

Extended Capabilities

Fixed-Point Conversion
Design and simulate fixed-point systems using Fixed-Point Designer™.

Version History

Introduced before R2006a