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, seeStateflow.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 Data | Method for Sizing Data | ||
---|---|---|---|
Inherit the Size | Use Numeric Values | Use MATLAB Expressions | |
Local | Only in charts that use MATLAB as the action language | Yes | Yes |
Constant | No | Yes | Yes |
Parameter | Yes | Yes | Yes |
Input | Yes | Yes | Yes |
Output | Yes | Yes | Yes |
Data store memory | Yes | No | No |
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, entern
.To specify a 1-by-
n
row vector, enter[1
.n
]To specify an
n
-by-m
matrix, enter[
, wheren
m
]m
andn
are greater than1
.To specify an
n
-dimensional array, enter[
, whered1
d2
⋯dn
]di
is the size of thei
th 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 butRed
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
, whereK
is a chart-level Stateflow constant or parameter.N/2
, whereN
is a variable in the MATLAB base workspace.[P Q]
, whereP
andQ
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
, whereRed
is an enumerated value of typeColors
.size(u)
, whereu
is a chart-level variable. The functionsize
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 thesize
function and specifying the size of the data directly.floor((a*b)/c)
, wherea
andc
are scalars of typeint16
andb
is a scalar of typedouble
.[fi(2,1,16,2) fi(4,1,16,2)]
. This expression specifies a data size of[2 4]
by calling the functionfi
(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.
Priority | Variable |
---|---|
1 | Mask parameter |
2 | Model workspace variable |
3 | MATLAB base workspace variable |
4 | Stateflow 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
orImportedDefine
with a specified header fileCompilerFlag
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
fi
(Fixed-Point Designer) | size