| Stateflow® | ![]() |
| On this page… |
|---|
Stateflow data can be a scalar, vector, or N-dimensional matrix, depending on its scope (see Size).
Note Stateflow vectors and matrices use zero-based indexing, unlike MATLAB vectors and matrices, which use one-based indexing. |
You specify the size of Stateflow data as a scalar value or a MATLAB vector of values in the Size field of the Data properties dialog box, as described in Properties You Can Set in the General Pane.
You can enter size as a constant value or an expression. Stateflow input and output data objects can also inherit their sizes from the Simulink signals that connect to them.
In the Data properties dialog box, you specify scalar data by setting the Size field to 1 or leaving it blank.
You specify MATLAB vectors and matrices as multidimensional arrays, where the number of dimensions equals the length of the vector, and the size of each dimension corresponds to the value of each element of the vector. Enter the size of two-dimensional arrays in [row column] format.
One-dimensional Stateflow data arrays are compatible with Simulink row or column vectors of the same size. For example, Stateflow input or output data of size 3 is compatible with a Simulink row vector of size [1,3], or column vector of size [3,1]. To define a row vector of size 5, set the Size field to [1 5]. To define a column vector of size 6, set the Size field to [6 1] or just 6.
You can use a mathematical expression to set the size of Stateflow data. Size expressions must evaluate to a positive integer.
In the Size field of the Data properties dialog box, you can enter a MATLAB expression for each dimension. Expressions can contain a mix of numeric constants, Stateflow constants, arithmetic operators, parameters, and calls to functions such as size, min, and max. Valid size expressions include:
k+1 size(x) min(size(y),k)
For more information about expressions, see Entering Expressions and Parameters for Data Properties.
Note You cannot size Stateflow input data with an expression that accepts frame-based data from Simulink models. |
To configure Stateflow input and output data objects to inherit size from the corresponding Simulink input and output signals, enter -1 in the Size field of the Data properties dialog box. This default setting applies to input and output data that you add in the Stateflow Editor (see Adding Data). After you build your model, the Compiled Size column of the Model Explorer displays the actual size that the compiled simulation application uses.
Note Stateflow blocks in libraries can inherit data sizes. However, multiple instances of the same library in a model must inherit the same data size. |
In the following example, the input data invals connects to a Constant block that specifies a four-element vector. The Compiled Size column displays the correct inherited size of 4 for invals.

Inheriting the size of input data is complete for all cases. Chart actions that store values in the specified output infer the inherited size of output data. If the expected size in the Simulink model matches the inferred size, inheritance is successful. Otherwise, a mismatch occurs during build time.
Note Stateflow charts cannot inherit frame-based data sizes from Simulink models. |
![]() | Typing Stateflow Data | Defining Temporary Data | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |