| Contents | Index |
| On this page… |
|---|
Rules for Defining Structure Data Types in Charts Defining Structure Inputs and Outputs |
Follow these rules when defining structures in Stateflow charts:
You must define each structure as a Simulink.Bus object in the base workspace.
You cannot define structures for Stateflow machines.
Note The Stateflow machine is the object that contains all other Stateflow objects in a Simulink model (see Stateflow Hierarchy of Objects). |
Structures cannot have these scopes: Constant or Data Store Memory.
Structures of parameter scope must be tunable.
Data array objects cannot contain structures.
Structures cannot contain arrays of buses.
You can drive Stateflow structure inputs by using any Simulink bus signal that has matching properties. Similarly, Stateflow charts can output structures to Simulink blocks that accept bus signals.
To create inputs and outputs in Stateflow charts:
Create a Simulink bus object in the base workspace to define the structure type for your Stateflow chart.
For information about how to create Simulink bus objects, see Simulink.Bus in the Simulink Reference documentation.
Select Tools > Explore in the Stateflow Editor to open the Model Explorer.
In the Model Explorer, add a data object as described in Adding Data Using the Model Explorer.
The Model Explorer adds a data object and opens a Properties dialog box in its right-hand Dialog pane.
In the Name field of the Properties dialog box, enter the name of the structure data.
In the Scope field, select either Input or Output.
In the Type field, select Inherit: Same as Simulink, Bus: <object name>, or <data type expression> according to these guidelines:
| Type | Works with Scope | Requirements |
|---|---|---|
| Inherit: Same as Simulink | Input | You do not need to specify a value. The data type is inherited from previously-defined data, based on the scope you selected for the data object. There must be a Simulink bus signal in your model that connects to the Stateflow structure input. The Simulink bus signal must be a nonvirtual bus (see Working with Virtual and Nonvirtual Buses). You must specify a Simulink.Bus object in the base workspace with the same properties as the bus signal in your model that connects to the Stateflow structure input. The following properties must match:
If your input signal comes from a Bus Creator block, you must specify an appropriate bus object for Output data type in the Bus Creator dialog box. When you specify the bus object, Simulink verifies that the properties of the Simulink.Bus object in the base workspace match the properties of the Simulink bus signal. |
| Bus: <object name> | Input or Output | Replace "<object name>" in the Type field with the name of the Simulink.Bus object in the base workspace that defines the Stateflow structure. For example: Bus: inbus. |
| <date type expression> | Input or Output | Replace "<data type expression>"
in the Type field with an expression that evaluates
to a data type. Enter the expression according to these guidelines:
|
Click Apply.
Simulink models support virtual and nonvirtual buses. Virtual buses read their inputs from noncontiguous memory, while nonvirtual buses read their inputs from data structures stored in contiguous memory (see Virtual and Nonvirtual Buses in the Simulink documentation).
Stateflow charts support nonvirtual buses only. When Simulink models contain Stateflow structure inputs and outputs, a hidden converter block converts bus signals for use with Stateflow charts, as follows:
Converts incoming virtual bus signals to nonvirtual buses for Stateflow structure inputs
Converts outgoing nonvirtual bus signals from Stateflow charts to virtual bus signals, if necessary
Even though this conversion process allows Stateflow charts to accept virtual and nonvirtual buses as input, Stateflow structures cannot inherit properties from virtual bus input signals. If the input to a chart is a virtual bus, you must set the data type mode of the Stateflow bus input to Bus Object, as described in Interfacing Stateflow Structures with Simulink Bus Signals.
To define local structures:
Create a Simulink bus object in the base workspace to define the structure type for your Stateflow chart.
For information about how to create Simulink bus objects, see Simulink.Bus in the Simulink Reference documentation.
Select Tools > Explore in the Stateflow Editor to open the Model Explorer.
In the Model Explorer, add a data object as described in Adding Data Using the Model Explorer.
The Model Explorer adds a data object and opens a Properties dialog box in its right-hand Dialog pane.
In the Name field of the Properties dialog box, enter the name of the structure data.
In the Scope field, select Local.
In the Type field, select either Bus: <object name>, or <data type expression>, and then specify the expression as follows:
| Type | What to Specify |
|---|---|
| Bus: <object name> | Replace "<object name>" in the Type field with the name of the Simulink.Bus object in the base workspace that defines the Stateflow structure. For example: Bus: inbus. |
| <date type expression> | Replace "<data type expression>"
in the Type field with an expression that evaluates
to a data type. You can enter any of the following expressions:
|
Click Apply.
To define structures of parameter scope:
Create a Simulink bus object in the base workspace to define the structure type for your chart.
For information about how to create Simulink bus objects, see Simulink.Bus in the Simulink Reference documentation.
Select Tools > Explore in the Stateflow Editor to open the Model Explorer.
In the Model Explorer, add a data object as described in Adding Data Using the Model Explorer.
The Model Explorer adds a data object and opens a Properties dialog box in its right-hand Dialog pane.
In the Name field of the Properties dialog box, enter the name of the structure data.
In the Scope field, select Parameter.
In the Type field, select either Bus: <object name>, or <data type expression>, and then specify the expression as follows:
| Type | What to Specify |
|---|---|
| Bus: <object name> | Replace "<object name>" in the Type field with the name of the Simulink.Bus object in the base workspace that defines the Stateflow structure. For example: Bus: inbus. |
| <date type expression> | Replace "<data type expression>"
in the Type field with an expression that evaluates
to a data type. You can enter any of the following expressions:
|
Click Apply.
Tip Stateflow structures with parameter scope must be tunable. To ensure tunability, open the Configuration Parameters dialog box and clear the Inline parameters check box on the Optimization > Signals and Parameters pane. In this case, each element in the structure is tunable. For more information, see Tunable Parameters in the Simulink documentation. |
You can define temporary structures in truth tables, graphical functions, and MATLAB functions of a Stateflow chart.
To define a temporary structure:
Create a Simulink bus object in the base workspace to define the structure type for your chart.
For information about how to create Simulink bus objects, see Simulink.Bus in the Simulink Reference documentation.
Select Tools > Explore in the Stateflow Editor to open the Model Explorer.
In the Model Explorer, add a data object to your function as described in Adding Data Using the Model Explorer.
The Model Explorer adds a data object and opens a Properties dialog box in its right-hand Dialog pane.
In the Name field of the Properties dialog box, enter the name of the structure data.
In the Scope field, select Temporary.
In the Type field, select either Bus: <object name>, or <data type expression>, and then specify the expression as follows:
| Type | What to Specify |
|---|---|
| Bus: <object name> | Replace "<object name>" in the Type field with the name of the Simulink.Bus object in the base workspace that defines the Stateflow structure. For example: Bus: inbus. |
| <date type expression> | Replace "<data type expression>"
in the Type field with an expression that evaluates
to a data type. You can enter any of the following expressions:
|
Click Apply.
You can define structure types with expressions that call the Stateflow type operator. This operator assigns the type of your structure based on the type of another structure defined in the Stateflow chart. For example, the model sfbus_demo contains a local structure whose type is defined using a type operator expression, as follows:

In this case, the structure counterbus_struct derives its type from structure inbus, which is defined by the Simulink.Bus object COUNTERBUS. Therefore, the structure counterbus_struct is also defined by the bus object COUNTERBUS.
To learn how to use the Stateflow type operator, see Deriving Data Types from Previously Defined Data.
![]() | About Stateflow Structures | Structure Operations | ![]() |

Learn how engineers use Stateflow to model state machines in their Simulink models.
| © 1984-2012- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |