When you create Stateflow® charts in Simulink®, you can specify data properties in either the Property Inspector or the Model Explorer.
Open the Symbols window by selecting View > Symbols.
Open the Property Inspector by selecting View > Property Inspector.
In the Symbols window, select the data object.
In the Property Inspector, edit the data properties.
Open the Model Explorer by selecting View > Model Explorer.
In the Contents pane, select the data object.
In the Data pane, edit the data properties.
Properties vary according to the scope and type of the data object. For many data properties, you can enter expressions or parameter values. Using parameters to set properties for many data objects simplifies maintenance of your model because you can update multiple properties by changing a single parameter.
You can set these data properties in:
The main and Advanced sections of the Property Inspector.
The General tab of the Model Explorer.
Name of the data object. For more information, see Rules for Naming Stateflow Objects.
Location where data resides in memory, relative to its parent.
Data defined in the current chart only.
Read-only constant value that is visible to the parent Stateflow object and its children.
Constant whose value is defined in the MATLAB® base workspace or derived from a Simulink block parameter that you define and initialize in the parent masked subsystem. The Stateflow data object must have the same name as the MATLAB variable or the Simulink parameter. For more information, see Share Parameters with Simulink and the MATLAB Workspace.
Input argument to a function if the parent is a graphical function, truth table, or MATLAB function. Otherwise, the Simulink model provides the data to the chart through an input port on the Stateflow block. For more information, see Share Input and Output Data with Simulink.
Return value of a function if the parent is a graphical function, truth table, or MATLAB function. Otherwise, the chart provides the data to the Simulink model through an output port on the Stateflow block. For more information, see Share Input and Output Data with Simulink.
Data object that binds to a Simulink data store, which is a signal that functions like a global variable. All blocks in a model can access that signal. This binding allows the chart to read and write to the Simulink data store, sharing global data with the model. The Stateflow object must have the same name as the Simulink data store. For more information, see Access Data Store Memory from a Chart.
Data that persists during only the execution of a function. For C charts, you can define temporary data only for a graphical function, truth table, or MATLAB function.
Data from the Simulink model that is made available to external code defined in the Stateflow hierarchy. You can define exported data only for a Stateflow machine.
Data parented by the Simulink model that you define in external code embedded in the Stateflow machine. You can define imported data only for a Stateflow machine.
Index of the port associated with the data object. This property applies only to input and output data. See Share Input and Output Data with Simulink.
Specifies whether a variable updates in discrete or continuous time. This property applies only when the chart is configured for continuous-time simulation. See Continuous-Time Modeling in Stateflow.
Specifies that output or local data explicitly inherits properties from
Simulink.Signal objects of the same name in the MATLAB base workspace or the Simulink model workspace. The data can inherit these properties:
Sampling mode (for Truth Table block output data)
This option is available only when you set the model configuration parameter
Signal resolution to a value other than
For more information, see Resolve Data Properties from Simulink Signal Objects.
Size of the data object. The size can be a scalar value or a MATLAB vector of values. To specify a scalar, set the Size property to 1 or leave it blank. To specify a MATLAB vector, use a multidimensional array. The number of dimensions equals the length of the vector and the size of each dimension that corresponds to the value of each vector element.
The scope of the data object determines what sizes you can specify. Stateflow data store memory inherits all its properties, including its size, from the Simulink data store to which it is bound. For all other scopes, size can be scalar, vector, or a matrix of n-dimensions.
For more information, see Specify Size of Stateflow Data.
Specifies that the data object changes dimensions during simulation. This option is available for input and output data only when you enable the chart property Support variable-size arrays. For more information, see Declare Variable-Size Data in Stateflow Charts.
Specifies whether the data object accepts complex values.
|Data object does not accept complex values.|
|Data object accepts complex values.|
|Data object inherits the complexity setting from a Simulink block.|
The default value is
Off. For more information, see
Complex Data in Stateflow Charts.
Index of the first element of the data array. The first index can be any non-negative
integer. The default value is
0. This property is available only for C
Type of data object. To specify the data type:
From the Type drop-down list, select a built-in type.
In the Type field, enter an expression that evaluates to a data type.
Use the Data Type Assistant to specify a data Mode, and then specify the data type based on that mode. To display the Data Type Assistant, in the Model Explorer, click the Show data type assistant button . The Data Type Assistant is available only in the Model Explorer.
For more information, see Specify Type of Stateflow Data.
If you enter an expression for a fixed-point data type, you must specify scaling
explicitly. For example, you cannot enter an incomplete specification such as
fixdt(1,16) in the Type field. If you do not specify
scaling explicitly, an error appears when you try to simulate your model.
Prevents replacement of the current fixed-point type with an autoscaled type chosen by the Fixed-Point Tool (Fixed-Point Designer). For more information, see Autoscaling Using the Fixed-Point Tool (Fixed-Point Designer).
Specifies physical units for input and output data. For more information, see Specify Units for Stateflow Data.
Initial value of the data object. The options for initializing values depend on the scope of the data object.
|Scope||Specify for Initial Value|
|Expression or parameter defined in the Stateflow hierarchy, MATLAB base workspace, or Simulink masked subsystem|
|Constant value or expression. The expression is evaluated when you update the chart. The resulting value is used as a constant for running the chart.|
|You cannot enter a value. The chart inherits the initial value from the parameter.|
|You cannot enter a value. The chart inherits the initial value from the Simulink input signal on the designated port.|
|Expression or parameter defined in the Stateflow hierarchy, MATLAB base workspace, or Simulink masked subsystem.|
|You cannot enter a value. The chart inherits the initial value from the Simulink data store to which it resolves.|
If you do not specify a value, the default value for numeric data is 0. For
enumerated data, the default value is the first one listed in the
enumeration section of the definition, unless you specify otherwise in the
methods section of the definition. For more information, see Enter Expressions and Parameters for Data Properties.
Specifies that local, constant, or output data inherits its initial value from a Simulink parameter in the MATLAB base workspace. For more information, see Initialize Data from the MATLAB Base Workspace.
Range of acceptable values for this data object. Stateflow charts use this range to validate the data object during simulation.
Minimum — The smallest value allowed for the data item during simulation. You can enter an expression or parameter that evaluates to a numeric scalar value.
Maximum — The largest value allowed for the data item during simulation. You can enter an expression or parameter that evaluates to a numeric scalar value.
The smallest value that you can set for Minimum is
-inf. The largest value that you can set for Maximum
inf. For more information, see Enter Expressions and Parameters for Data Properties.
A Simulink model uses the Limit range properties to calculate best-precision scaling for fixed-point data types. Before you select Calculate Best-Precision Scaling, specify a minimum or maximum value. For more information, see Calculate Best-Precision Scaling.
Enables watching the data values in the Stateflow Breakpoints and Watch window. For more information, see Watch Stateflow Data Values.
In the Model Explorer, when you set the Data Type Assistant Mode to
Fixed point, the Data Type Assistant displays fields for specifying
additional information about your fixed-point data.
Specifies whether the fixed-point data is
Unsigned. Signed data can represent positive and negative values.
Unsigned data represents positive values only. The default setting is
Specifies the bit size of the word that holds the quantized integer. Large word sizes represent large values with greater precision than small word sizes. The default value is 16.
Word length can be any integer from 0 through 128 for chart-level data of these scopes:
Data Store Memory
For other Stateflow data, word length can be any integer from 0 through 32.
Specifies the method for scaling your fixed-point data to avoid overflow conditions and
minimize quantization errors. The default method is
If you select this mode, the Data Type Assistant displays the Fraction length field, which specifies the binary point location.
Fraction length can be any integer. The default value is 0. A positive integer moves the binary point left of the rightmost bit by that amount. A negative integer moves the binary point farther right of the rightmost bit.
If you select this mode, the Data Type Assistant displays fields for entering the Slope and Bias for the fixed-point encoding scheme.
Slope can be any positive real number. The default value is 1.0.
Bias can be any real number. The default value is 0.0.
You can enter slope and bias as expressions that contain parameters you define in the MATLAB base workspace.
Whenever possible, use binary-point scaling to simplify the implementation of fixed-point data in generated code. Operations with fixed-point data that use binary-point scaling are performed with simple bit shifts and eliminate expensive code implementations required for separate slope and bias values. For more information about fixed-point scaling, see Scaling (Fixed-Point Designer).
Specifies whether to inherit the data type override setting of the Fixed-Point Tool that
applies to this model. If the data does not inherit the model-wide setting, the specified data
type applies. For more information about the Fixed-Point Tool, see
Specifies whether to calculate the best-precision values for
Slope and bias scaling, based on the values
in the Minimum and Maximum
fields in the Limit range section.
To calculate best-precision scaling values:
Specify Limit range properties.
Click Calculate Best-Precision Scaling.
Simulink software calculates the scaling values and displays them in the Fraction length field or the Slope and Bias fields. For more information, see Constant Scaling for Best Precision (Fixed-Point Designer).
The Limit range properties do not apply to
Parameter scopes. For
Constant, Simulink software calculates the scaling values based on the Initial
value setting. The software cannot calculate best-precision scaling for data of
Displays information about the fixed-point data type that is defined in the Data Type Assistant:
Maximum show the same values that
appear in the corresponding Minimum and Maximum fields in the Limit range
Representable maximum, and
Precision show the minimum value, maximum value, and precision that the
fixed-point data type can represent.
If the value of a field cannot be determined without first compiling the model,
the Fixed-point details subpane shows the value as
The values displayed by the Fixed-point details subpane do not automatically update if you change the values that define the fixed-point data type. To update the values shown in the Fixed-point details subpane, click Refresh Details.
Clicking Refresh Details does not modify the model. It changes only the display. To apply the displayed values, click Apply or OK.
The Fixed-point details subpane indicates any error resulting from the fixed-point data type specification. For example, this figure shows two errors.
The row labeled
Maximum indicates that the value specified in the
Maximum field of the Limit range section is not
representable by the fixed-point data type. To correct the error, make one of these
modifications so the fixed-point data type can represent the maximum value:
Decrease the value in the Maximum field of the Limit range section.
Increase Word length.
Decrease Fraction length.
The row labeled
Minimum shows the error
evaluate because evaluating the expression
MySymbol, specified in
the Minimum field of the Limit range section, does
not return a numeric value. When an expression does not evaluate successfully, the
Fixed-point details subpane shows the unevaluated expression (truncating
to 10 characters as needed) in place of the unavailable value. To correct this error, define
MySymbol in the base workspace to provide a numeric value. If you click
Refresh Details, the error indicator and description are removed and
the value of
MySymbol appears in place of the unevaluated text.
You can set logging properties for data in:
The Logging section of the Property Inspector.
The Logging tab of the Model Explorer.
Saves the data value to the MATLAB base workspace during simulation. For more information, see Log Simulation Output for States and Data.
Designates the data as a test point. A test point is a signal that you can observe in a Floating Scope block in a model. Data objects can be test points if:
Parent is not a Stateflow machine.
Data type is not
For more information, see Monitor Test Points in Stateflow Charts.
Specifies the name associated with logged signal data. Simulink software uses the signal name as its logging name by default. To specify a custom
logging name, select
Custom from the list box and enter the new name
in the adjacent edit field.
Limits the amount of data logged to the most recent samples.
Limits the amount of data logged by skipping samples. For example, a decimation factor of 2 saves every other sample.
You can set additional data properties in:
The Info tab of the Property Inspector.
The Description tab of the Model Explorer.
Assigns the value of the data item to a variable of the same name in the MATLAB base workspace at the end of simulation. This option is available only in the Model Explorer for C charts. For more information, see Model Workspaces (Simulink).
Units of measurement associated with the data object. The unit in this field resides with the data object in the Stateflow hierarchy. This property is available only in the Model Explorer for C charts.
Description of the data object. You can enter brief descriptions of data in the hierarchy.
Link to online documentation for the data object. You can enter a web URL address or a MATLAB command that displays documentation in a suitable online format, such as an HTML file or text in the MATLAB Command Window. When you click the Document link hyperlink, Stateflow evaluates the link and displays the documentation.
In the Property Inspector and Model Explorer, you can enter expressions as values for these properties:
Expressions can contain a mix of parameters, constants, arithmetic operators, and calls to MATLAB functions.
When you leave an expression or parameter field blank, Stateflow assumes a default value.
You can include parameters in expressions. A parameter is a constant value that you can:
Define in the MATLAB base workspace.
Derive from a Simulink block parameter that you define and initialize in the parent masked subsystem.
You can mix both types of parameters in an expression. For more information, see Share Parameters with Simulink and the MATLAB Workspace.
For expressions in the Data properties dialog box, you can use numeric constants of the appropriate type and size. Do not use Stateflow constants in these expressions.
In the Data properties dialog box, you can use these arithmetic operators in expressions:
In fields that accept expressions, you can call functions that return property values of other variables defined in the Stateflow hierarchy, MATLAB base workspace, or Simulink masked subsystem. For example, these functions can return appropriate values for specified fields in the Data properties dialog box.
|Stateflow operator ||Type of input data||Data type|
|Simulink function ||Data type|
|MATLAB function ||Smallest element or elements of input array||Minimum|
|MATLAB function ||Largest element or elements of input array||Maximum|