You can specify the size of Stateflow^{®} data by:
Inheriting the size from a Simulink^{®} signal
Using numeric values
Using MATLAB^{®} expressions
Support for a 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 | No | Yes | Yes |
Constant | No | Yes | Yes |
Parameter | No | Yes | Yes |
Input | Yes | Yes | Yes |
Output | Yes | Yes | Yes |
Data store memory | Yes | No | No |
Stateflow data store memory inherits all data properties, including size, from the Simulink data store to which it resolves. You cannot specify any properties explicitly for data store memory.
To specify the size of Stateflow data in the Data properties dialog box, you use the Size field, as described in Properties You Can Set in the General Pane. For more information, see:
To specify the size of Stateflow data using API commands,
you set the Props.Array.Size
property to a numeric
value or a MATLAB expression that represents a scalar, vector,
matrix, or n-dimensional array. For more information on using the
API, see Stateflow.Data Properties in the Stateflow API documentation.
To configure Stateflow input and output data 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 to your chart. After you build your model, the Compiled Size column of the Model Explorer displays the actual size that the compiled simulation application uses.
The equivalent API command for specifying an inherited data size is:
data_handle.Props.Array.Size = '-1';
Chart actions that store values in the specified output infer the inherited size of output data. If the expected size in the Simulink signal matches the inferred size, inheritance is successful. Otherwise, a mismatch occurs during build time.
Note: Charts cannot inherit frame-based data sizes from Simulink signals. |
When you specify data size using numeric values in the Size field of the Data properties dialog box, follow these guidelines:
Dimensionality | What to Specify in the Dialog Box | Equivalent API Command |
---|---|---|
Scalar |
| data_handle .Props.Array.Size
= '1'; data_handle .Props.Array.Size
= ''; |
Vector | The number of elements in the row or column vector | data_handle .Props.Array.Size
= ' |
Matrix | An expression of the format
| data_handle .Props.Array.Size
= '[r c]'; |
N-dimensional array | An expression of the format
| data_handle .Props.Array.Size
= '[Size_of_dim1 Size_of_dim2 ... Size_of_dimN]; |
One-dimensional Stateflow vectors 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]
.
When you specify data size using MATLAB expressions, follow the same guidelines that apply to sizing with numeric values (see Guidelines for Sizing Data with Numeric Values). The following guidelines also apply.
Expressions that specify the size of a dimension:
Can contain a mix of numeric values, variables, arithmetic operators, parameters, and calls to MATLAB functions.
Must evaluate to a positive integer value.
To specify inherited data size, you must enter –1
in the Size field or set the Props.Array.Size
property
for the data to –1. Expressions cannot evaluate to a value
of –1.
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.
You cannot size Stateflow input data with an expression that accepts frame-based data from Simulink.
The following examples are valid MATLAB expressions for sizing data in your chart:
K+3
, where K
is
a chart-level Stateflow data
N/2
, where N
is
a variable in the MATLAB base workspace
2*Colors.Red
, where Red
is
an enumerated value of type Colors
[fi(2,1,16,2) fi(4,1,16,2)]
, which
specifies a data size of [2 4]
using a signed fixed-point
type with word length of 16 and fraction length of 2
When multiple variables with identical names exist in a model, the variable with the highest priority applies:
Mask parameters
Model workspace
MATLAB base workspace
Stateflow data