This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

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 through the Symbols window, the Chart menu in the Stateflow Editor, or the Model Explorer.

Add Data Through the Symbols Window

  1. To open the Symbols window, select View > Symbols.

  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 window, 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
    InputChart > Add Inputs & Outputs > Data Input From Simulink
    OutputChart > Add Inputs & Outputs > Data Output To Simulink
    LocalChart > Add Other Elements > Local Data
    ConstantChart > Add Other Elements > Constant
    ParameterChart > Add Other Elements > Parameter
    Data Store MemoryChart > Add Other Elements > Data Store Memory

  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 Stateflow Editor, select View > 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

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

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