Main Content

Specify Size of Stateflow Data

In Stateflow® charts, data size determines memory allocation, affects simulation performance, and ensures compatibility between Stateflow charts and connected Simulink® blocks. Incorrect sizing can lead to compilation errors, runtime failures, or unexpected behavior.

In a Stateflow chart in a Simulink model, specify the size of a data object by using the Property Inspector or the Stateflow API.

  • In the Property Inspector, you can set the Size property, as described in Set Data Properties.

  • With the Stateflow API, you can set the Size property.

Data Scope and Sizing Method Compatibility

You can specify data size by specifying a numeric value, a MATLAB expression, or by opting to inherit the size from Simulink. The method you use to specify size depends on your data scope.

Scope of DataInherit the SizeUse Numeric ValuesUse MATLAB Expressions
LocalOnly in charts that use MATLAB as the action languageYesYes
ConstantNoYesYes
ParameterYesYesYes
InputYesYesYes
OutputYesYesYes
Data store memoryYesNoNo

For more information about data scope, see Specify Scope and Type of Stateflow Data.

Specify Data Size by Using Numeric Values

When you specify data size by entering numeric values, use these guidelines.

Data TypeSize SpecificationExample
ScalarEnter 1 or leave the field blank1
Column vector (n×1)Enter the number of rows5
Row vector (1×n)Enter [1 n][1 5]
Matrix (n×m)Enter [n m][3 4]
N-dimensional arrayEnter [d₁ d₂ ⋯ dₙ][2 3 4]

In charts that use C as the action language, one-dimensional Stateflow vectors are compatible with Simulink row or column vectors of the same size. For example, a Stateflow input data of size 3 is compatible with either:

  • A Simulink row vector of size [1 3]

  • A Simulink column vector of size [3 1]

Specify Data Size by Using Expressions

You can specify data size using MATLAB expressions that evaluate to valid size specifications. Expressions provide flexibility for charts that need dynamic sizing based on parameters or other data.

Expressions can contain:

  • Numeric values and constants

  • Parameters and variables

  • Arithmetic operations (+, -, *, /).

  • MATLAB function calls. For example, size, length, floor.

Expressions must evaluate to positive integer values for each dimension.

Values must be type-compatible, such as integers with integers, scalars with compatible types.

Enumerated values must include the type prefix. For example, Colors.Red, not Red.

Expression Limitations

You cannot use MATLAB expressions to:

  • Specify inherited data size. In other words, expressions cannot evaluate to -1.

  • Specify the size of Stateflow input data that accepts frame-based data from Simulink. For more information, see Sample- and Frame-Based Concepts (DSP System Toolbox).

These examples are valid MATLAB expressions for specifying data size in your chart:

  • K+3, where K is a chart-level Stateflow constant or parameter.

  • N/2, where N is a variable in the MATLAB® base workspace.

  • [P Q], where P and Q are Simulink parameters. Charts that use C as the action language propagate these symbolic dimensions throughout the model. See Propagate Symbolic Dimensions of Stateflow Data.

  • 2*Colors.Red, where Red is an enumerated value of type Colors.

  • size(u), where u is a chart-level variable. The function size enables you to specify the size of one data object based on the size of another data object. This type of expression is useful in a library chart that you reuse with data of different sizes. In other situations, you can improve the clarity of your chart by avoiding the size function and specifying the size of the data directly.

  • floor((a*b)/c), where a and c are scalars of type int16 and b is a scalar of type double.

  • [fi(2,1,16,2) fi(4,1,16,2)]. This expression specifies a data size of [2 4] by calling the function fi (Fixed-Point Designer). This function returns signed fixed-point numbers with a word length of 16 and a fraction length of 2.

Inherit Data Size

To configure a Stateflow data object to inherit its size from a Simulink signal or its definition in the chart, specify a size of –1. This approach is useful when:

  • The data size is determined by the connected Stateflow signal.

  • You want to maintain flexibility for reusable charts.

  • The size may change based on model configuration.

After you simulate or build your model, you can find the inherited size of the data in the Model Explorer, under the CompiledSize column.

Propagate Symbolic Dimensions of Stateflow Data

When you select the model configuration parameter Allow symbolic dimension specification, charts that use C as the action language can propagate symbolic dimensions throughout the model.

Propagate Symbolic Dimensions of Stateflow Data

When you select the model configuration parameter Allow symbolic dimension specification, charts that use C as the action language can propagate the symbolic dimensions of Stateflow data throughout the model. If you have Embedded Coder®, the symbolic dimensions go into the generated code for ERT targets. Specify the size of the symbolic dimensions by using Simulink parameters with one of these storage classes:

  • Define or ImportedDefine with a specified header file

  • CompilerFlag

  • A user-defined custom storage class that defines data as a macro in a specified header file

For more information, see Allow symbolic dimension specification (Simulink) and Implement Symbolic Dimensions for Array Sizes in Generated Code (Embedded Coder).

Stateflow charts that use MATLAB as the action language do not support symbolic dimension propagation. To specify data size by using Simulink parameters, clear the Allow symbolic dimension specification check box.

See Also

(Fixed-Point Designer) |

Topics