Size Stateflow Data

Methods for Sizing Stateflow Data

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 DataMethod for Sizing Data
Inherit the SizeUse Numeric ValuesUse MATLAB Expressions
LocalNoYesYes
ConstantNoYesYes
ParameterNoYesYes
InputYesYesYes
OutputYesYesYes
Data store memoryYesNoNo

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.

How to Specify Data Size

Use the Size Field of the Data Properties Dialog Box

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:

Set the Stateflow.Data Object Property

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.

Inherit Input or Output Size from Simulink Signals

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.

Guidelines for Sizing Data with Numeric Values

When you specify data size using numeric values in the Size field of the Data properties dialog box, follow these guidelines:

DimensionalityWhat to Specify in the Dialog BoxEquivalent API Command

Scalar

1 (or leave the field blank)

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 = 'number_of_elements';

Matrix

An expression of the format
[r c], where:

  • r is the number of rows

  • c is the number of columns

data_handle.Props.Array.Size = '[r c]';

N-dimensional array

An expression of the format
[Size_of_dim1 Size_of_dim2 ... Size_of_dimN], where:

  • Size_of_dim1 is the size of the first dimension

  • Size_of_dim2 is the size of the second dimension

  • Size_of_dimN is the size of the N-th dimension

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].

Guidelines for Sizing Data with MATLAB Expressions

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.

Examples of Valid Data Size Expressions

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

Name Conflict Resolution for Variables in Size Expressions

When multiple variables with identical names exist in a model, the variable with the highest priority applies:

  1. Mask parameters

  2. Model workspace

  3. MATLAB base workspace

  4. Stateflow data

Best Practices for Sizing Stateflow Data

 Avoid use of variables that can lead to naming conflicts

 Avoid use of size(u) expressions

Was this topic helpful?