Add Data

When to Add Data

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

Where You Can Use Data

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.

Data defined in a Stateflow chart can be used by multiple Stateflow objects in the chart, such as states, MATLAB® functions and truth tables. Stateflow data is not available to Simulink functions within Stateflow.

Diagnostic for Detecting Unused Data

If you have unused data in your chart, a warning appears during simulation with a list of data you can remove. By removing objects that have no effect on simulation, you can reduce the size of your model. This diagnostic checks for usage of Stateflow data, except for the following types:

  • Machine-parented data

  • Inputs and outputs of MATLAB functions

  • Data of parameter scope in a chart that contains atomic subcharts

After you select data for removal, a dialog box confirms your choice. In this dialog box, you can specify that other deletions occur without confirmation. If you prevent the confirmation dialog box from appearing, you can reenable it at any time by typing at the command prompt:

sfpref('showDeleteUnusedConfGui', 1)

You can control the level of diagnostic action for unused data in the Diagnostics > Stateflow pane of the Model Configuration Parameters dialog box. For more information, see the documentation for the Unused data, events and messages diagnostic.

Add Data Using the Stateflow Editor

  1. Based on the desired scope for the new data, select one of the following 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

    The Data properties dialog box appears after you select one of those options.

  2. Specify properties for the new data in the Data properties dialog box, as described in Set Data Properties.

How to Add Data Using the Model Explorer

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

    The Model Explorer opens.

  2. In the Model Hierarchy pane, select the object in the Stateflow hierarchy where you want the new data to be 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, and the data definition appears in a new row in the Model Explorer.

  4. Change the properties of the data, as described in Set Data Properties.

Was this topic helpful?