A Stateflow® structure is a data type that you define from a
Simulink.Bus (Simulink) object. Using Stateflow structures, you can bundle data of different size and type to create:
Inputs and outputs that access Simulink® bus signals from Stateflow charts, Truth Table blocks, and MATLAB Function blocks.
Local data in Stateflow charts, truth tables, graphical functions, MATLAB® functions, and boxes.
Temporary data in Stateflow graphical functions, truth tables, and MATLAB functions.
For more information, see Create and Specify Simulink.Bus Objects (Simulink).
In this example, a Stateflow chart receives a bus input signal by using the structure
inbus and outputs a bus signal from the structure
outbus. The input signal comes from the Simulink Bus Creator block
COUNTERBUSCreator, which bundles signals from two other Bus Creator blocks. The output structure
outbus connects to a Simulink Bus Selector block. Both
outbus derive their type from the
COUNTERBUS. For more information about this example, see Integrate Custom Structures in Stateflow Charts.
The elements of a Stateflow structure data type are called fields. Fields can be any combination of individual signals, muxed signals, vectors, and other structures (also called substructures). Each field has its own data type. The data type does not have to match the type of any other field in the structure. For example, in this model, each of the structures
outbus has two fields:
inputsignal is a substructure with one field,
limits is a substructure with two fields,
To define the structure data type, create a Simulink bus object in the base workspace, as described in Create and Specify Simulink.Bus Objects (Simulink).
Add a data object to the chart, as described in Add Stateflow Data.
To define temporary structures in truth tables, graphical functions, and MATLAB functions, add a data object to your function. For more information, see Add Data Through the Model Explorer.
Set the Scope property for the structure. Your choices are:
Data Store Memory
Temporary (Only in charts that use C as the action
Set the Type property for the structure. Depending on its scope, a Stateflow structure can have one of these data types.
This option is available for input structures only. The input structure inherits its data type from the Simulink bus signal in your model that connects to it. The Simulink bus signal must be a nonvirtual bus. For more information, see Virtual and Nonvirtual Buses.
In the base workspace, specify a
If the input signal comes from a Bus Creator
block, in the Bus Creator dialog box, specify an appropriate bus object for
Output data type field. When you specify the bus
object, Simulink verifies that the properties of the
In the Type field, replace
For input or output structures, you are
not required to specify the bus signal in your Simulink model that connects to the Stateflow structure. If you do specify a bus signal, its properties must
In the Type field, replace
For example, in the
sf_bus_demo model, the input structure
inbus and the output structure
outbus derive their
type through a type specification of the form
To specify structure types, you can use expressions that call the Stateflow
type operator. This operator
sets the type of one structure to the type of another structure in the Stateflow chart. For example, in the
sf_bus_demo model, a
type operator expression specifies the type of the local structure
counterbus_struct in terms of the input structure
inbus. Both structures are defined from the
COUNTERBUS. For more
information, see Derive Data Types from Other Data Objects.
Simulink models support virtual and nonvirtual buses. Nonvirtual buses read their inputs from data structures stored in contiguous memory. Virtual buses read their inputs from noncontiguous memory. For more information, see Types of Composite Signals (Simulink).
Stateflow charts support only nonvirtual buses. Stateflow input structures can accept virtual bus signals and convert them to nonvirtual
bus signals. Stateflow input structures cannot inherit properties from virtual bus signals. If the
input to a chart is a virtual bus, set the Type property of the input
structure through a type specification of the form
To debug a Stateflow structure, open the Stateflow Breakpoints and Watch window and examine the values of structure fields during simulation. To view the values of structure fields at the command line, use dot notation to index into the structure. For more information, see Inspect and Modify Data and Messages While Debugging.
Define each structure from a
Simulink.Bus object in the base
Structures cannot have a constant scope.
Structures of parameter scope must be tunable.