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.
Enable Support for Variable-Size Data
Support for variable-size data is enabled by default. To enable or disable this option for individual charts,modify the chart property Support variable-size arrays, as described in Specify Properties for Stateflow Charts.
Declare Variable-Size Data
After enabling support at the chart level, you can declare variable-size data by following these steps:
Add a data object to the chart, as described in Add Stateflow Data.
Set Scope property as
Charts that use C as the action language do not support variable-size local data.
Select the Variable size check box.
Use the Size property to explicitly specify the maximum size for the data. For example, to specify a 2-D matrix where the maximum size is 2 for the first dimension and 4 for the second dimension, in the Size field, enter
Guidelines for Using Variable-Size Data
Stateflow charts that use MATLAB® as the action language can access and modify variable-size input, output, and local data in state and transition actions.
In contrast, charts that use C as the action language can only exchange variable-size input and output data with other charts and Simulink blocks by using:
Truth tables that use MATLAB as the action language
When you use variable-size data in a C chart, these guidelines apply:
Declare variable-size data as chart inputs and outputs only, and not as local data.
To define variable-size chart inputs that inherit their size from the Simulink model, set the Size property to
All computations with variable-size data must occur inside functions, and not directly in states or transitions.
You can pass variable-size data as inputs and outputs to these functions from state and transition actions. In addition, MATLAB functions can access the chart-level, variable-size data directly.