Main Content

Specify Size of Stateflow Data

In a Stateflow® chart in a Simulink® model, you specify the size of a data object by:

  • Setting the Size property, as described in Set Data Properties. For more information, see Size.

  • Setting the Props.Array.Size property through the Stateflow API. For more information, see Stateflow.Data.

Use one of these methods to specify the size:

  • Inherit the size from a Simulink signal or from its definition in the Stateflow chart.

  • Enter a numeric value.

  • Enter a MATLAB® expression.

Support for each sizing method depends on the scope of your data.

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

Inherit Data Size

To configure a Stateflow data object to inherit its size from the corresponding Simulink signal or its definition in the chart, specify a size of –1. After you simulate or build your model, you can find the inherited size of the data in the Model Explorer, under the CompiledSize column.

Note

Charts cannot inherit data sizes from Simulink frame-based signals. For more information, see Sample- and Frame-Based Concepts (DSP System Toolbox).

Specify Data Size by Using Numeric Values

When you specify data size by entering a numeric value, follow these guidelines:

  • To specify a scalar, enter 1 or leave the field blank.

  • To specify an n-by-1 column vector, enter n.

  • To specify a 1-by-n row vector, enter [1 n].

  • To specify an n-by-m matrix, enter [n m], where m and n are greater than 1.

  • To specify an n-dimensional array, enter [d1 d2dn], where di is the size of the ith dimension.

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 a Simulink row vector of size [1 3] or a column vector of size [3 1].

Specify Data Size by Using Expressions

You can specify data size by entering a MATLAB expression that evaluates to one of the size specifications described in Specify Data Size by Using Numeric Values. These guidelines also apply:

  • Expressions can contain a mix of numeric values, constants, parameters, variables, arithmetic operations, and calls to MATLAB functions.

  • Expressions that specify the size of a dimension must evaluate to a positive integer value.

  • Expressions can only combine compatible values. For example, integers can only be combined with other integers of the same type or with scalar doubles.

  • If the expression contains an enumerated value, you must include the type prefix for consistency with MATLAB naming rules. For example, Colors.Red is valid but Red is not. For more information, see Notation for Enumerated Values.

  • You cannot use a MATLAB expression to:

    • Specify inherited data size. Do not use expressions that 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).

Examples of Valid Data Size Expressions

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.

Avoid Variables That Can Lead to Naming Conflicts

When a model contains multiple variables with identical names, the variable with the highest priority is used to specify size.

PriorityVariable
1Mask parameter
2Model workspace variable
3MATLAB base workspace variable
4Stateflow data

To avoid confusion, do not specify data size by using a variable name that you define in multiple levels of your 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) |

Related Topics