Simulink.NumericType - Specify floating-point, integer, or fixed-point data type - MATLAB (original) (raw)
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.
- 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.
- Set the properties of the object to create a custom floating point, integer, or fixed point data type.
- 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 orModel Explorer. - Programmatically create a
Simulink.NumericType
object using theSimulink.NumericType
function described here.
Syntax
Description
typeObj = Simulink.NumericType
returns aSimulink.NumericType
object with default property values.
Properties
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.
Value | Action |
---|---|
'Auto' (default) | If no value is specified forHeaderFile, export the type definition to_model__types.h.model is the model name.If a value is specified forHeaderFile, 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 theHeaderFile 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 theHeaderFile 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
orExported
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 MATLABdouble
type.'Single'
— Same as the MATLABsingle
type.'Half'
— Half-precision floating-point type.'Boolean'
— Same as the MATLABboolean
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
andSlope
properties accordingly, and vice versa. This property applies only if the DataTypeMode
isFixed-point: binary point scaling
orFixed-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
ifDataScope
equals 'Imported'
or'Exported'
, or defaults to_`model`__types.h
ifDataScope
equals 'Auto'
.
By default, the generated #include
directive uses the preprocessor delimiter "
instead of<
and >
. To generate the directive #include <myTypes.h>
, specifyHeaderFile
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 as2^SlopeAdjustmentFactor
. Otherwise, it displays it as a numeric value. Setting this property causes Simulink software to set the FixedExponent
andSlopeAdjustmentFactor
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
isFixed-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 ifDataTypeMode
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
isFixed-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
isboolean | Determine whether numeric type represents the Boolean data typeboolean |
---|---|
isdouble | Determine whether numeric type represents the double-precision, floating-point data type double |
isfixed | Determine whether numeric type represents a fixed-point data type |
isfloat | Determine whether numeric type represents a floating-point data type |
isscalingbinarypoint | Determine whether fixed-point numeric type has binary-point scaling |
isscalingslopebias | Determine whether numeric type represents a fixed-point data type with slope-and-bias scaling |
isscalingunspecified | Determine whether numeric type represents a data type with unspecified scaling |
issingle | Determine whether numeric type represents the single-precision, floating-point data type single |
ishalf | Determine whether numeric type represents the half-precision, floating-point data type half |
Examples
Extended Capabilities
When you select the Is alias property, aSimulink.NumericType
object appears in the generated code as atypedef
statement. The generated code uses the named type to define and declare data (variables).
Version History
Introduced before R2006a