Declare Variable-Size Data in Stateflow Charts

Variable-size data is data whose size can change at run time. In contrast, fixed-size data is data whose size is known and locked at compile time and does not change at run time. Use variable-size data if the output from a Stateflow® chart in a Simulink® model is an array whose size depends on the state of the chart.

Stateflow charts exchange variable-size data with other charts and blocks in their models through MATLAB® functions, Simulink functions, and truth tables that use MATLAB as the action language. You pass variable-size data to these functions as chart-level inputs and outputs from state actions and transition logic. However, you must perform all computations with variable-size data inside the functions, not directly in states or transitions. For more information about the functions that interact with variable-size, chart-level inputs and outputs, see:

Enable Support for Variable-Size Data

Support for variable-size data is enabled by default. To modify this option for individual charts:

  1. Right-click an open area of the chart and select Properties.

  2. In the Chart properties dialog box, select or clear the Support variable-size arrays check box.

After enabling support at the chart level, you can declare variable-size inputs and outputs.

Declare Variable-Size Inputs and Outputs

  1. Add a data object to the chart, as described in Add Stateflow Data.

  2. Set Scope property as Input or Output.

  3. Select the Variable size check box.

  4. Set the Size property for the data.

    ScopeWhat to Specify
    Input

    Enter -1 to inherit size from Simulink or specify the explicit size and upper bound.

    OutputSpecify the explicit size and upper bound.

    For example, this specification declares a variable-size input data that inherits its Size and Type from the Simulink model. To specify a 2-D matrix where the upper bounds are 2 for the first dimension and 4 for the second dimension, in the Size field, enter [2 4] instead.

Rules for Using Variable-Size Data

  • Declare variable-size data as chart inputs and outputs only, not as local data.

    See Declare Variable-Size Inputs and Outputs.

  • Do not perform computations with variable-size data directly in states or transitions.

  • Perform all computations with variable-size data in MATLAB functions, Simulink functions, and truth tables that use MATLAB as the action language.

    You can pass the data as inputs and outputs to MATLAB and Simulink functions in your chart from state actions and transition logic. MATLAB functions can also access the chart-level, variable-size data directly. For more information, see Compute Output Based on Size of Input Signal.

Related Topics