The term data type refers to how computers represent information in memory. The data type determines the amount of storage allocated to data, the method of encoding a data value as a pattern of binary digits, and the operations available for manipulating the data.
You can specify the type of a data object in either the Property Inspector or the Model Explorer. In the Type field, select a type from the drop-down list or enter an expression that evaluates to a data type. For more information, see Set Data Properties.
Alternatively, use the Data Type Assistant to specify a data Mode and select the data type based on that mode:
In the Model Explorer, on the Data pane, click the Show
data type assistant button .
Select a Mode from the drop-down list. The list of available modes depends on the scope of the data object.
Scope | Modes |
---|---|
Local | Inherit (available only in charts that use MATLAB® as the action language), Built in ,
Fixed point , Enumerated ,
Bus object , Expression |
Constant | Built in , Fixed point ,
Expression |
Parameter | Inherit , Built
in , Fixed point ,
Enumerated , Bus object ,
Expression |
Input | Inherit , Built
in , Fixed point ,
Enumerated , Bus object ,
Expression |
Output | Inherit , Built
in , Fixed point ,
Enumerated , Bus object ,
Expression |
Data Store Memory | Inherit |
Specify additional information based on the mode. The Data Type Assistant populates the Type field based on your specification.
Mode | Data Types |
---|---|
Inherit | You cannot specify a data type. You inherit the data type based on the scope that you select for the data object:
For more information, see Inherit Data Types from Simulink Objects. |
Built in | Specify a data type from the drop-down list of supported data types:
|
Fixed point | Specify this information about the fixed-point data:
For information, see Fixed-Point Data Properties. |
Enumerated | Specify the class name for the enumerated data type. For more information, see Define Enumerated Data Types. |
Bus object | Specify the name of a |
Expression | Specify an expression that evaluates to a data type. Use one of these expressions:
For more information, see Specify Data Properties by Using MATLAB Expressions. |
To save the data type settings, click Apply.
The Data Type Assistant is available only through the Model Explorer.
When you select Inherit: Same as Simulink
from the
Type drop-down list, data objects of scope
Input
, Output
,
Parameter
, and Data Store Memory
inherit
their data types from Simulink objects.
Scope | Description |
---|---|
Input | Inherits type from the Simulink input signal connected to corresponding input port in chart. |
Output | Inherits type from the Simulink output signal connected to corresponding output port in chart. Avoid inheriting data types from output signals. Values that back-propagate from Simulink blocks can be unpredictable. |
Parameter | Inherits type from the corresponding MATLAB base workspace variable or Simulink parameter in a masked subsystem. |
Data Store Memory | Inherits type from the corresponding Simulink data store. |
To determine the data types that the objects inherit:
Build the Simulink model.
Open the Model Explorer.
In the Contents pane, examine the CompiledType column.
You can use the type
operator to derive data types from other
Stateflow data
objects:
type(data_obj)
sf_bus_demo
, the expression type(inbus)
returns
the data type of the input structure inbus
. Because inbus
derives its type from the Simulink.Bus
object COUNTERBUS
,
the data type of the local structure counterbus_struct
also derives its data
type from COUNTERBUS
.After you build your model, the CompiledType column of the Model Explorer shows the type used in the compiled simulation application.
You can specify the type of Stateflow data by using a Simulink data type alias. For more information, see Simulink.AliasType
.
For example, suppose that you want to define a data type alias MyFloat
that corresponds to the built-in data type single
. At the MATLAB command prompt, enter:
MyFloat = Simulink.AliasType;
MyFloat.BaseType = 'single';
To use this alias to specify the type of a data object, select the object in the Property
Inspector or the Model Explorer. In the Type field, enter the alias name
MyFloat
.
After you build your model, the CompiledType column of the Model Explorer shows the type used in the compiled simulation application.
By default, the Use Strong Data Typing with Simulink I/O chart property allows C charts to interface directly with signals from Simulink models. The chart accepts only input signals whose data type matches the type of the corresponding Stateflow data object. Otherwise, a type mismatch error occurs. For example, by selecting Use Strong Data Typing with Simulink I/O, you can flag mismatches between input or output fixed-point data in charts and their counterparts in Simulink models. For more information, see Specify Properties for Stateflow Charts.
If you clear the Use Strong Data Typing with Simulink I/O chart property, the chart converts inputs signals of type
double
to the type of the corresponding input data object in the
chart. The chart converts output data objects to type double
before
exporting them as output signals to Simulink models.
Note
The Use Strong Data Typing with Simulink I/O chart property is provided for backward compatibility. Clearing this check box can produce unpredictable results and is not recommended.
fixdt
| Simulink.AliasType
| Simulink.NumericType