Skip to Main Content Skip to Search
Product Documentation

Sizing Stateflow Data

Methods for Sizing Stateflow Data

You can specify the size of Stateflow data by:

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

Using 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:

Setting 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 Data Properties in the Stateflow API documentation.

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

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.

Examples of Valid Data Size Expressions

The following examples are valid MATLAB expressions for sizing data in your chart:

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

  


Free Stateflow Interactive Kit

Learn how engineers use Stateflow to model state machines in their Simulink models.


Get free kit

Trials Available

Try the latest version of Stateflow.


Get trial software
 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS