Main Content

Set Data Properties

When you create Stateflow®charts in Simulink®, you can modify data properties in theProperty Inspectoror the Model Explorer.

To use theProperty Inspector:

  1. In theModelingtab, underDesign Data, selectSymbols PaneandProperty Inspector.

  2. In theSymbolspane, select the data object.

  3. In theProperty Inspector, edit the data properties.

To use the Model Explorer:

  1. In theModelingtab, underDesign Data, selectModel Explorer.

  2. In theModel Hierarchypane, select the parent of the data object.

  3. In theContentspane, select the data object.

  4. In theDialogpane, edit the data properties.

You can also modify these properties programmatically by usingStateflow.Dataobjects. For more information about the Stateflow programmatic interface, seeOverview of the Stateflow API.

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.

StateflowData Properties

You can set these data properties in:

  • ThePropertiestab of theProperty Inspector.

  • TheGeneraltab of the Model Explorer.

Name

Name of the data object. For more information, seeGuidelines for Naming Stateflow Objects.

Scope

Location where data resides in memory, relative to its parent.

Setting Description
Local

Data defined in the current chart only.

Constant

Read-only constant value that is visible to the parent Stateflow object and its children.

Parameter

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, seeShare Parameters with Simulink and the MATLAB Workspace.

Input

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, seeShare Input and Output Data with Simulink.

Output

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, seeShare Input and Output Data with Simulink.

Data Store Memory

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, seeAccess Data Store Memory from a Chart.

Temporary

数据持续期间的执行function. You can define temporary data only for graphical functions, truth tables, or MATLAB functions in charts that use C as the action language.

Port

Index of the port associated with the data object. This property applies only to input and output data. SeeShare Input and Output Data with Simulink.

Update method

Specifies whether a variable updates in discrete or continuous time. This property applies only when the chart is configured for continuous-time simulation. SeeContinuous-Time Modeling in Stateflow.

Data must resolve to signal object

Specifies that output or local data explicitly inherits properties fromSimulink.Signalobjects of the same name in the MATLAB base workspace or the Simulink model workspace. The data can inherit these properties:

  • 大小

  • Complexity

  • Type

  • Unit

  • Minimum value

  • Maximum value

  • Initial value

  • Storage class

  • Sampling mode (for Truth Table block output data)

This option is available only when you set the model configuration parameterSignal resolution以外的一个值None. For more information, seeResolve Data Properties from Simulink Signal Objects.

大小

大小of the data object. The size can be a scalar value or a MATLAB vector of values.

  • To specify a scalar, set the大小property to1or leave the field blank.

  • To specify ann-by-1 column vector, set the大小property ton.

  • To specify a 1-by-nrow vector, set the大小property to[1n].

  • To specify ann-by-mmatrix, set the大小property to[nm].

  • To specify ann-dimensional array, set the大小property to[d1d2dn], wherediis the size of theithdimension.

  • To configure a Stateflow data object to inherit its size from the corresponding Simulink signal or from its definition in the chart, specify a size of–1.

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, seeSpecify Size of Stateflow Data.

You can specify data size through a MATLAB expression that evaluates to a valid size specification. For more information, seeSpecify Data Size by Using ExpressionsandSpecify Data Properties by Using MATLAB Expressions.

Variable size

Specifies that the data object changes size during simulation. This option is available only when you enable the chart propertySupport variable-size arrays. For more information, seeDeclare Variable-Size Data in Stateflow Charts.

Complexity

Specifies whether the data object accepts complex values.

Setting Description
Off Data object does not accept complex values.
On Data object accepts complex values.
Inherited Data object inherits the complexity setting from a Simulink block.

The default value isOff. For more information, seeComplex Data in Stateflow Charts.

First index

Index of the first element of the data array. The first index can be any integer. The default value is0. This property is available only for C charts.

Type

Type of data object. To specify the data type:

Additionally, in the Model Explorer, you can open the Data Type Assistant by clicking theShow data type assistantbutton. Specify a dataMode, and then specify the data type based on that mode. For more information, seeSpecify Type of Stateflow Data.

Note

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 asfixdt(1,16)in theTypefield. If you do not specify scaling explicitly, an error appears when you try to simulate your model.

Lock data type against Fixed-Point tools

Prevents replacement of the current fixed-point type with an autoscaled type chosen by theFixed-Point Tool(Fixed-Point Designer). For more information, seeIterative Fixed-Point Conversion Using the Fixed-Point Tool(Fixed-Point Designer).

Unit (e.g., m, m/s^2, N*m)

Specifies physical units for input and output data. For more information, seeSpecify Units for Stateflow Data.

Initial value

Initial value of the data object. For constant data, this property is calledConstant value. The options for specifying this property depend on the scope of the data object.

Scope Specify for Initial Value
Local

Expression or parameter defined in the Stateflow hierarchy, MATLAB base workspace, or Simulink masked subsystem. To specify the initial value when you leave theInitial valuefield blank, open the Model Explorer or the Data properties dialog box and set theInitial valuedrop-down list toExpressionorParameter.

  • Expression— Numeric data resolves to a default value of 0. For enumerated data, the default value typically is the first one listed in theenumerationsection of the definition. You can specify a different default enumerated value in themethodssection of the definition. For more information, seeDefine Enumerated Data Types.

  • Parameter— The data object resolves to a variable in the base workspace with the same name.

The default setting isExpression.

Constant

常量值或表达式。表达式是电动汽车aluated when you update the chart. The resulting value is used as a constant for running the chart.

When you leave theConstant valuefield blank, numeric data resolves to a default value of 0. For enumerated data, the default value typically is the first one listed in theenumerationsection of the definition. You can specify a different default enumerated value in themethodssection of the definition. For more information, seeDefine Enumerated Data Types.

Parameter You cannot enter a value. The chart inherits the initial value from the parameter.
Input You cannot enter a value. The chart inherits the initial value from the Simulink input signal at the designated port.
Output

Expression or parameter defined in the Stateflow hierarchy, MATLAB base workspace, or Simulink masked subsystem. To specify the initial value when you leave theInitial valuefield blank, open the Model Explorer or the Data properties dialog box and set theInitial valuedrop-down list toExpressionorParameter.

  • Expression— Numeric data resolves to a default value of 0. For enumerated data, the default value typically is the first one listed in theenumerationsection of the definition. You can specify a different default enumerated value in themethodssection of the definition. For more information, seeDefine Enumerated Data Types.

  • Parameter— The data object resolves to a variable in the base workspace with the same name.

The default setting isExpression.

Data Store Memory You cannot enter a value. The chart inherits the initial value from the Simulink data store to which it resolves.

The time of initialization depends on the data parent and scope of the Stateflow data object.

Data Parent

Scope

Initialization Time

Chart

Input

Not applicable

Output, Local

Start of simulation or when chart reinitializes as part of an enabled Simulink subsystem

State with History Junction

Local

Start of simulation or when chart reinitializes as part of an enabled Simulink subsystem

State without History Junction

Local

State entry

Function (graphical, truth table, and MATLAB functions)

Input, Output

Function-call invocation

Local

Start of simulation or when chart reinitializes as part of an enabled Simulink subsystem

For more information on using an expression to specify an initial value, seeSpecify Data Properties by Using MATLAB Expressions.

Limit range

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 forMinimumis-inf. The largest value that you can set forMaximumisinf.

You can specify the minimum and maximum values through a MATLAB expression. For more information, seeSpecify Data Properties by Using MATLAB Expressions.

Note

A Simulink model uses theMaximumandMinimumproperties to calculate best-precision scaling for fixed-point data types. Before you selectCalculate Best-Precision Scaling, specify a minimum or maximum value. For more information, seeCalculate best-precision scaling.

Fixed-Point Data Properties

In the Model Explorer, when you set the Data Type AssistantModetoFixed point, the Data Type Assistant displays fields for specifying additional information about your fixed-point data.

Data Type Assistant showing the fields used to specify fixed-point data.

Signedness

Specifies whether the fixed-point data isSignedorUnsigned. Signed data can represent positive and negative values. Unsigned data represents positive values only. The default setting isSigned.

Word length

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:

    • Input

    • Output

    • Parameter

    • Data Store Memory

  • For other Stateflow data, word length can be any integer from 0 through 32.

You can specify the word length through a MATLAB expression. For more information, seeSpecify Data Properties by Using MATLAB Expressions.

Scaling

Specifies the method for scaling your fixed-point data to avoid overflow conditions and minimize quantization errors. The default method isBinary pointscaling.

Setting Description
Binary point

If you select this mode, the Data Type Assistant displays theFraction lengthfield, which specifies the binary point location.

Fraction lengthcan 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.

Schematic showing the relationship between the word length and fraction length properties for fixed-point data.

Slope and bias

If you select this mode, the Data Type Assistant displays fields for entering theSlopeandBiasfor the fixed-point encoding scheme.

Slopecan be any positive real number. The default value is 1.0.

Biascan 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, seeScaling(Fixed-Point Designer).

You can specifyFraction length,Slope, andBiasthrough a MATLAB expression. For more information, seeSpecify Data Properties by Using MATLAB Expressions.

Data type override

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.

Calculate best-precision scaling

Specifies whether to calculate the best-precision values forBinary pointandSlope and biasscaling, based on the values in theMinimumandMaximumproperties.

To calculate best-precision scaling values:

  1. SpecifyMaximumandMinimumproperties.

  2. ClickCalculate Best-Precision Scaling.

The best-precision scaling values are displayed in theFraction lengthfield or theSlopeandBiasfields.For more information, seeMaximize Precision(Fixed-Point Designer).

Note

TheMaximumandMinimumproperties do not apply toConstantandParameterscopes. ForConstant, Simulink software calculates the scaling values based on theInitial valuesetting. The software cannot calculate best-precision scaling for data ofParameterscope.

Fixed-point details

Displays information about the fixed-point data type that is defined in the Data Type Assistant:

  • MinimumandMaximumshow the same values that you specify in theMinimumandMaximumproperties.

  • Representable minimum,Representable maximum, andPrecision显示,米inimum 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, theFixed-point detailssubpane shows the value asUnknown.

Fixed-point details subpane showing the maximum and minimum values for the data object data.

The values displayed by theFixed-point detailssubpanedo notautomatically update if you change the values that define the fixed-point data type. To update the values shown in theFixed-point detailssubpane, clickRefresh Details.

ClickingRefresh Detailsdoes not modify the model. It changes only the display. To apply the displayed values, clickApplyorOK.

TheFixed-point detailssubpane indicates any error resulting from the fixed-point data type specification. For example, this figure shows two errors.

Fixed-point details subpane showing two specification errors because the data object has invalid maximum and minimum values.

The row labeledMaximumindicates that the value specified by theMaximumproperty 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 theMaximumproperty.

  • IncreaseWord length.

  • DecreaseFraction length.

The row labeledMinimumshows the errorCannot evaluatebecause evaluating the expressionMySymbol, specified by theMinimumproperty, does not return a numeric value. When an expression does not evaluate successfully, theFixed-point detailssubpane shows the unevaluated expression (truncating to 10 characters as needed) in place of the unavailable value. To correct this error, defineMySymbolin the base workspace to provide a numeric value. If you clickRefresh Details, the error indicator and description are removed and the value ofMySymbolappears in place of the unevaluated text.

Logging Properties

You can set logging properties for data in:

  • ThePropertiestab of theProperty Inspector.

  • TheLoggingtab of the Model Explorer.

Log signal data

Whether to enable signal logging. Signal logging saves the values of the data object to the MATLAB workspace during simulation. For more information, seeLog Simulation Output for States and Data.

Logging name

Signal name used to log the data object.

  • To use the name of the data object, selectUse signal name(default).

  • To specify a different name, selectCustomand enter the custom logging name.

Limit data points to last

Whether to limit the number of data points to log to the specified maximum. For example, if you set the maximum number of data points to 5000, the chart logs only the last 5000 data points generated by the simulation.

Decimation

Whether to limit the amount of logged data by skipping samples using the specified decimation interval. For example, if you set a decimation interval of 2, the chart logs every other sample.

Test point

Whether to set the data object as a test point that you can monitor with a floating scope during simulation. You can also log test point values to the MATLAB workspace. For more information, seeMonitor Test Points in Stateflow Charts.

Additional Properties

You can set additional data properties in:

  • TheInfotab of theProperty Inspector.

  • TheDescriptiontab of the Model Explorer.

Save final value to base workspace

Assigns the value of the data object 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 charts that use C as the action language. For more information, seeModel Workspaces(Simulink).

Units

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

Description of the data object.

Document link

链接到在线文档的数据对象。You can enter a web URL address or a MATLAB command that displays documentation as an HTML file or as text in the MATLAB Command Window. When you click theDocument linkhyperlink, Stateflow evaluates the link and displays the documentation.

Default Data Property Values

当你离开一个属性字段空白,Stateflowssumes a default value.

Property Default Value
大小

−1(inherited), for inputs, parameters, and function outputs

1(scalar), for other data objects

First index 0
Initial value 0.0
Limit range Minimum -inf
Maximum inf
Fixed-Point Data Properties Word length 16
Fraction length 0
Slope 1.0
Bias 0.0

Specify Data Properties by UsingMATLABExpressions

In theProperty Inspectorand Model Explorer, you can enter MATLAB expressions as values for these properties:

Expressions can contain a mix of numeric values, constants, parameters, variables, arithmetic operations, parameters, constants, arithmetic operators, and calls to MATLAB functions. For example, you can use these functions to specify data properties.

Property Function Description
大小 size Returns the size of a data object
Type type Returns the type of a data object
fixdt(Simulink) Returns aSimulink.NumericTypeobject that describes a fixed-point or floating-point data type
fi(Fixed-Point Designer) Returns a fixed-point numeric object
Minimum min Returns the smallest element or elements of an array
Maximum max Returns the largest element or elements of an array

For more information, seeSpecify Data Size by Using ExpressionsandDerive Data Types from Other Data Objects.

See Also

Objects

Functions

Tools

Related Topics