Main Content

Add Stateflow Data

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.

Note

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.

Add Data Through the Symbols Pane

  1. In the Modeling tab, under Design Data, select Symbols Pane.

  2. Click the Create Data icon .

  3. In the row for the new data, under TYPE, click the icon and choose:

    • Input Data

    • Local Data

    • Output Data

    • Constant

    • Data Store Memory

    • Parameter

    • Temporary

  4. Edit the name of the data.

  5. For input and output data, click the PORT field and choose a port number.

  6. 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.

Add Data by Using the Stateflow Editor Menu

  1. In a Stateflow chart in a Simulink model, select the menu option corresponding to the scope of the data that you want to add.

    ScopeMenu Option
    Input

    In the Modeling tab, under Design Data, select Data Input.

    Output

    In the Modeling tab, under Design Data, select Data Output.

    Local

    In the Modeling tab, under Design Data, select Local.

    Constant

    In the Modeling tab, under Design Data, select Constant.

    Parameter

    In the Modeling tab, under Design Data, select Parameter.

    Data Store Memory

    In the Modeling tab, under Design Data, select Data Store.

  2. In the Data dialog box, specify data properties. For more information, see Stateflow Data Properties.

Add Data Through the Model Explorer

To add machine or state-parented data to Stateflow charts in Simulink models, use the Model Explorer:

  1. In the Modeling tab, under Design Data, select Model Explorer.

  2. 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.

  3. In the Model Explorer menu, select Add > Data. The new data with a default definition appears in the Contents pane of the Model Explorer.

  4. In the Data pane, specify the properties of the data. For more information, see Stateflow Data Properties.

Best Practices for Using Data in Charts

Avoid Inheriting Output Data Properties from Simulink Blocks

Stateflow output data should not inherit properties from output signals, because the values back propagate from Simulink blocks and can be unpredictable.

Restrict Use of Machine-Parented Data

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:

  • Enumerated data

  • Simulink functions

  • Chart operating point

  • Implicit change events

  • Detection of unused data

  • Parameters binding to a Simulink.Parameter object in the base workspace

  • Model referencing (see Model Reference Requirements and Limitations )

  • 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.

Related Topics