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 an object of the class Simulink.AliasType.

Creation

To create a Simulink.NumericType object interactively, use the Model Explorer:

  1. On the Model Explorer Model Hierarchy pane, select a workspace, such as the base workspace, or a data dictionary.

  2. From the Model Explorer Add menu, select Simulink.NumericType.

    The Model Explorer creates an instance of a Simulink.NumericType object and assigns it to a variable named Numeric in the target workspace.

  3. Rename the variable to a more appropriate name, for example, a name that reflects its intended usage.

    To change the name, edit the name displayed in the Name field on the Model Explorer Contents pane.

  4. On the Model Explorer Dialog pane, use the Data type mode property to select a data type that the object represents.

To create a Simulink.NumericType object programmatically, use the Simulink.NumericType function described below.

Syntax

typeObj = Simulink.NumericType

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.

Corresponds to Bias in the property dialog box.

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.

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

Corresponds to Data scope in the property dialog box.

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.

  • '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 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 option installed.

Corresponds to Data type mode in the property dialog box.

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.

Corresponds to Data type override in the property dialog box.

Data Types: char

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

Corresponds to Description in the property dialog box.

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 does not appear in the property dialog box.

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.

Corresponds to Fraction length in the property dialog box.

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).

Corresponds to Header file in the property dialog box.

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 Control Data Type Names in Generated Code (Embedded Coder).

Corresponds to Is alias in the property dialog box.

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).

Corresponds to Signedness in the property dialog box.

Data Types: char

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

Corresponds to Signedness in the property dialog box.

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.

Corresponds to Slope in the property dialog box.

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 does not appear in the property dialog box.

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.

Corresponds to Word length in the property dialog box.

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

Examples

collapse all

Introduced before R2006a