Specify Type of Stateflow Data
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.
Specify Data Type by Using the Data Type Assistant
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 charts that use MATLAB as the action language, if scope is
Local
, the data infers its type from the context of the MATLAB code in the chart.If the scope is
Parameter
, the data inherits its type from the associated parameter, which you can define in the Simulink® model or in the MATLAB base workspace. See Share Parameters with Simulink and the MATLAB Workspace.If the scope is
Input
, the data inherits its type from the Simulink input signal on the designated input port. See Share Input and Output Data with Simulink.If the scope is
Output
, the data inherits its type from the Simulink output signal on the designated output port. See Share Input and Output Data with Simulink.Note
Avoid inheriting data types from output signals. See Avoid Inheriting Output Data Properties from Simulink Blocks.
If the scope is
Data Store Memory
, the data inherits its type from the Simulink data store to which you bind the data object. See Access Data Store Memory from a Chart.
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:
double
: 64-bit double-precision floating point.single
: 32-bit single-precision floating point.half
: A half-precision data type occupies 16 bits of memory, but its floating-point representation enables it to handle wider dynamic ranges than integer or fixed-point data types of the same size. See The Half-Precision Data Type in Simulink (Fixed-Point Designer).int64
: 64-bit signed integer.int32
: 32-bit signed integer.int16
: 16-bit signed integer.int8
: 8-bit signed integer.uint64
: 64-bit unsigned integer.uint32
: 32-bit unsigned integer.uint16
: 16-bit unsigned integer.uint8
: 8-bit unsigned integer.boolean
: Boolean (1 =true
; 0 =false
).ml
: Typed internally with the MATLAB arraymxArray
. Supported only in charts that use C as the action language. Theml
data type provides Stateflow data with the benefits of the MATLAB environment, including the ability to assign the Stateflow data object to a MATLAB variable or pass it as an argument to a MATLAB function.ml
data cannot have a scope outside the Stateflow hierarchy. That is, it cannot have a scope ofInput
orOutput
. For more information, see ml Data Type.string
: String. For more information, see Manage Textual Information by Using Strings.
Fixed point
Specify this information about the fixed-point data:
Signedness: Whether the data is signed or unsigned
Word length: Bit size of the word that holds the quantized integer. Large word sizes represent large values with greater precision than small word sizes. The default value is 16.
Scaling: Method for scaling your fixed-point data to avoid overflow conditions and minimize quantization errors. The default method is
Binary point
.
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
Simulink.Bus
object to associate with the Stateflow® bus object structure. Click Edit to create or edit a bus object in the Type Editor. You can also inherit bus object properties from Simulink signals.Expression
Specify an expression that evaluates to a data type. Use one of these expressions:
A call to the
fixdt
(Simulink) function to create aSimulink.NumericType
(Simulink) object that describes a fixed-point or floating-point data type. See Specify Fixed-Point Data.A call to the
type
operator to specify the type of previously defined data. See Derive Data Types from Other Data Objects.A
Simulink.AliasType
(Simulink) object that defines a data type alias in the MATLAB base workspace. See Specify Data Types by Using a Simulink Alias.
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.
Inherit Data Types from Simulink Objects
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, Simulink data dictionary entry, 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.
Derive Data Types from Other Data Objects
You can use the type
operator to derive data types
from other Stateflow data objects. For example, the model sf_bus_demo
uses the data
type of the input structure inbus
to define the data type of the local
structure counterbus_struct
by using this expression:
type(inbus)
Because inbus
derives its type from the Simulink.Bus
object COUNTERBUS
, counterbus_struct
also derives its data
type from COUNTERBUS
. After you compile your model, the
CompiledType column of the Model Explorer shows the type used in the
compiled simulation application.
For more information about this example, see Integrate Custom Structures in Stateflow Charts.
Specify Data Types by Using a Simulink Alias
You can specify the type of Stateflow data by using a Simulink data type alias. For more information, see Simulink.AliasType
(Simulink).
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.
Note
Stateflow blocks do not support code generation if one of the data uses an alias type and is variable size. This limitation does not apply to chart-level input, output, or local data. For more information on defining variable-size data, see Declare Variable-Size Data in Stateflow Charts.
See Also
fixdt
(Simulink) | Simulink.AliasType
(Simulink) | Simulink.NumericType
(Simulink)