Main Content

Add Stateflow Data

You can add data to a Stateflow® chart by using the Symbols pane or the toolstrip.

In Stateflow charts, data is accessible to states, transitions, MATLAB® functions, and truth tables. To examine which data a specific state or transition uses, right-click the state or transition and click Explore. This action opens a context menu that displays all resolved data in the selected state or transition, and their names and scopes. When you select a data from this menu, the Model Explorer opens and displays the properties of the data. If you select an output event the corresponding Simulink® subsystem or Stateflow chart linked to that event opens.

Note

Stateflow data is not available to Simulink functions in a Stateflow chart.

Add Data by Using the Symbols Pane

The Symbols pane displays all of the data objects in your chart. To create data in 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, in the Type column, click the icon and choose:

    • Input Data

    • Local Data

    • Output Data

    • Constant

    • Data Store Memory

    • Parameter

    • Temporary

    For more information about data types, see Set Data Properties.

  4. Edit the name of the data by setting the value in the Name column.

  5. For input and output data, you can change the order of the input or output ports by clicking the Port field and choose a port number.

  6. To specify properties for data, right-click the row for the symbol and select Explore.

Connect Data to Simulink

If you create an input or output data, you can connect them to Simulink blocks.

To connect input data:

  1. In your Simulink model, add a source block. See Sources (Simulink).

  2. Connect the source block output to the input port on your Stateflow chart.

When you click Run, the input data object receives values from the connected Simulink block.

To connect output data:

  1. In your Simulink model, add a sink block. See Sinks (Simulink).

  2. Connect the output port on your Stateflow chart to the destination block input.

When you click Run, the output data object sends values to the connected Simulink block.

Best Practices for Using Data in Charts

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

Optimize Performance of Generated Code by Using In-Place Data

To optimize performance and reduce memory usage in generated code for Stateflow charts, truth tables, and state transition tables, use in-place data. To create in-place data, assign identical names to chart inputs and output. In-place data allows the code generator to treat the data as a single argument passed by reference rather than separate variables. This approach minimizes intermediate data copying operations, resulting in more efficient generated code.

When input and output data share the same name, you can only modify properties for the input data. The corresponding output data properties become read-only.

See Also

Topics