Add Stateflow Data

Add data when you want to store values that are visible at a specific level of the Stateflow® hierarchy.

You can store and retrieve data that resides internally in the Stateflow workspace and externally in the Simulink® model or application that embeds the chart. Actions in your chart can refer to internal and external data.

You can use data defined in a Stateflow chart by multiple Stateflow objects in the chart. These objects can be states, transition, MATLAB® functions, and truth tables. Stateflow data is not available to Simulink functions within Stateflow.

Add Data from the Stateflow Editor

From the Stateflow editor, you can add data via the Symbols window or through menus.

To open the Symbols window, select View > Symbols. To add data in the Symbols window:

  1. Click the Create Data icon .

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

  3. Edit the name of the data.

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

To add data through menus, select one of these options:

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

You can edit properties for data in the Property Inspector or Data properties dialog box.

Add Data Through the Model Explorer

Add machine or state-parented data through the Model Explorer.

  1. In the Stateflow Editor, select View > Model Explorer.

  2. In the Model ExplorerModel Hierarchy pane, select the object in the Stateflow hierarchy where you want to make the new data visible.

    The object you select becomes the parent of the new data.

  3. In the Model Explorer, select Add > Data.

    The Model Explorer adds a default definition for the data in the hierarchy. The data definition appears in a new row in the Model Explorer.

  4. Change the properties of the data.

More About

Was this topic helpful?