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 through the Symbols window, the Chart menu in the Stateflow Editor, or the Model Explorer.
To open the Symbols window, select View > Symbols.
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 window, 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.
|Chart > Add Inputs & Outputs > Data Input From Simulink|
|Chart > Add Inputs & Outputs > Data Output To Simulink|
|Chart > Add Other Elements > Local Data|
|Chart > Add Other Elements > Constant|
|Chart > Add Other Elements > Parameter|
|Chart > Add Other Elements > Data Store Memory|
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 Stateflow Editor, select View > 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
Model referencing (see Model Reference Requirements and Limitations (Simulink) )
Analysis by Simulink Design Verifier™ software
Code generation by Simulink PLC Coder™ software
Parameters binding to a
Simulink.Parameter object in the base
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.