When you want to store values that are visible at a specific level of the Stateflow® hierarchy, add data to your chart.
Data defined in a Stateflow chart is visible by multiple Stateflow objects in the chart, including states, transitions, MATLAB® functions, and truth tables. To determine what data is used in a state or transition, right-click the state or transition and select Explore. A context menu lists the names and scopes of all resolved symbols in the state or transition. Selecting a symbol from the context menu displays its properties in the Model Explorer. Selecting an output event from the context menu opens the Simulink® subsystem or Stateflow chart associated with the event.
Stateflow data is not available to Simulink functions within a Stateflow chart.
You can add data to a Stateflow chart by using the Symbols pane, the Stateflow Editor menu, or the Model Explorer.
In the Modeling tab, under Design Data, select Symbols Pane.
Click the Create Data icon .
In the row for the new data, under TYPE, click the icon and choose:
Data Store Memory
Edit the name of the data.
For input and output data, click the PORT field and choose a port number.
To specify properties for data, open the Property Inspector. In the Symbols pane, right-click the row for the symbol and select Explore. For more information, see Stateflow Data Properties.
In a Stateflow chart in a Simulink model, select the menu option corresponding to the scope of the data that you want to add.
In the Modeling tab, under Design Data, select Data Input.
In the Modeling tab, under Design Data, select Data Output.
In the Modeling tab, under Design Data, select Local.
In the Modeling tab, under Design Data, select Constant.
In the Modeling tab, under Design Data, select Parameter.
In the Modeling tab, under Design Data, select Data Store.
In the Data dialog box, specify data properties. For more information, see Stateflow Data Properties.
To add machine or state-parented data to Stateflow charts in Simulink models, use the Model Explorer:
In the Modeling tab, under Design Data, select Model Explorer.
In the Model Hierarchy pane, select the object in the Stateflow hierarchy where you want to make the new data visible. The object that you select becomes the parent of the new data.
In the Model Explorer menu, select Add > Data. The new data with a default definition appears in the Contents pane of the Model Explorer.
In the Data pane, specify the properties of the data. For more information, see Stateflow Data Properties.
Stateflow output data should not inherit properties from output signals, because the values back propagate from Simulink blocks and can be unpredictable.
Avoid using machine-parented data. The presence of machine-parented data in a model prevents reuse of generated code and other code optimizations. This type of data is also incompatible with many Simulink and Stateflow features.
For example, the following features do not support machine-parented data:
Chart operating point
Implicit change events
Detection of unused data
Parameters binding to a
Simulink.Parameter object in the base
Model referencing (see Model Reference Requirements and Limitations (Simulink) )
Use of code replacement libraries in code generated by Embedded Coder®. For more information, see Code You Can Replace From Simulink Models (Embedded Coder).
Code generation by Simulink PLC Coder™ software
Analysis by Simulink Design Verifier™ software
To make Stateflow data accessible to other charts and blocks in a model, use data store memory. For details, see Access Data Store Memory from a Chart.