| Contents | Index |
| On this page… |
|---|
What Is a Stateflow Structure? |
A Stateflow structure is a data type that you define as a Simulink.Bus object. The elements of a Stateflow structure data type are called fields. The fields can be any combination of individual signals, muxed signals, vectors, and buses. Each field has its own data type, which need not match that of any other field.
With the Stateflow structure data type, you can create:
Inputs and outputs for accessing Simulink bus signals from Stateflow charts, Truth Table blocks, and MATLAB Function blocks (see Defining Structure Inputs and Outputs)
Local structure data in Stateflow charts, truth tables, graphical functions, MATLAB functions, and boxes (see Defining Local Structures)
Temporary structure data in Stateflow graphical functions, truth tables, and MATLAB functions (see Defining Temporary Structures)
The model sfbus_demo provides examples of structures in a Stateflow chart.

The chart contains a graphical function.

In this model, the Stateflow chart receives a bus input signal using the structure inbus at input port 1 and outputs a bus signal from the structure outbus at output port 1. The input signal comes from the Simulink Bus Creator block COUNTERBUSCreator, which bundles signals from two other Bus Creator blocks: SIGNALBUSCreator and LIMITBUSCreator. The structure outbus connects to a Simulink Bus Selector block BUSSelector. The Stateflow chart also contains a local structure counterbus_struct and a graphical function get_input_signal that contains an input structure u and output structure y.
Definitions of structures in the chart of the sfbus_demo model appear in the Model Explorer as follows:

Note The local structure counterbus_struct is defined using the type operator in an expression, as described in Defining Structure Types with Expressions. |
Definitions of structures in the graphical function get_input_signal appear in the Model Explorer as follows:

Each Stateflow structure must be defined by a Simulink.Bus object in the base workspace. The structure shares the same properties as the bus object, including number, name, and type of fields. For example, the sfbus_demo model defines the following bus objects in the base workspace:

You can find the bus object that defines a Stateflow structure by looking in the Data Type and Compiled Type columns in the Contents pane of the Model Explorer. For example, the structures inbus, outbus, and counterbus_struct are all defined in sfbus_demo by the same Simulink bus object, COUNTERBUS.
Based on these definitions, inbus, outbus, and counterbus_struct have the same properties as COUNTERBUS. For example, these Stateflow structures in sfbus_demo reference their fields by the same names as the elements in COUNTERBUS, as follows:
| Structure | First Field | Second Field |
|---|---|---|
| inbus | inbus.inputsignal | inbus.limits |
| outbus | outbus.inputsignal | outbus.limits |
| counterbus_struct | counterbus_struct.inputsignal | counterbus_struct.limits |
To learn how to define structures in Stateflow charts using Simulink.Bus objects, see Defining Stateflow Structures.
If you define a custom structure in C for your Stateflow chart, you must make sure that the structure's typedef declaration in your header file matches the properties of the Simulink.Bus object that defines the structure, as described in Integrating Custom Structures in Stateflow Charts.
![]() | Working with Structures and Bus Signals in Stateflow Charts | Defining Stateflow Structures | ![]() |

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 |