Stateflow    

Setting Data Properties

To change the properties for a data object in Stateflow, access its Data dialog as follows:

  1. Select Explore from the Stateflow editor's Tools menu.
  2. In the resulting Stateflow Explorer window, expand sections of the hierarchy to find the data whose properties you want to change.
  3. Right-click the data object in the Explorer's hierarchy pane (left pane).
  4. Select Properties from the resulting context menu.
  1. In place of steps 3 and 4 you could also simply select the data object and then select Properties from the Edit menu.

  1. In the resulting Data dialog, set the item's properties.

  1. Click OK to apply your changes and dismiss the Data dialog box.

The Data dialog box includes the following settings:

Name

Name of the data item. A data name can be of any length and can consist of any alphanumeric and special character combination, with the exception of embedded spaces. The name cannot begin with a numeric character.

Parent

Parent of this data item. The parent determines the objects that can access it. Specifically, only the item's parent and descendants of that parent can access the item. You specify the parent of a data item when you add the item to the data dictionary.

Scope

Scope of this data item. A data object's scope specifies where it resides in memory relative to its parent. These are the options for the Scope property:

Local.   A local data object resides and is accessible only in a machine, chart, or state.

Input from Simulink.   This is a data item that is accessible in a Simulink Chart block but resides in another Simulink block that might or might not be a Chart block. The receiving Chart block reads the value of the data item from an input port associated with the data item. See Importing Data for more information.

Output to Simulink.   This is a data item that resides in a Chart block and is accessible in another block that might or might not be a Chart block. The Chart block outputs the value of the data to an output port associated with the data item. See Defining Output Data for more information.

Temporary.   A temporary data item exists only while its parent is executing. See Defining Temporary Data for more information.

Constant.   A constant data object is read-only and retains the initial value set in its Data properties dialog box.

Exported.   An exported data item is data assigned to a Stateflow machine that can be accessed by external code that embeds that machine. See Exporting Data for more information.

Imported.   Imported data is data defined by external code that can be accessed by a Stateflow machine embedded in the external code. See Importing Data for more information.

Input.   Applies to a graphical function (arguments). See Creating a Graphical Function for more information.

Output.   Applies to a graphical function (return data). See Creating a Graphical Function for more information.

Type

Data type of this data. Select one of the following:

Type
Description
double
Double-precision floating-point (64 bit)
single
Single-precision floating-point (32 bit)
int32
32 bit signed integer
int16
16 bit signed integer
int8
8 bit signed integer
uint32
32 bit unsigned integer
uint16
16 bit unsigned integer
uint8
8 bit unsigned integer
boolean
Boolean
fixpt
Stateflow's fixed-point data type. Specify the fixed-point type through the Stored Integer and Scaling fields in the adjacent Fixed-Point field section, which is enabled when you specify the fixpt type.
See Fixed-Point Data for a description of the Stateflow fixed-point type and its use in Stateflow.
For fixed-point data, the Use Strong Data Typing with Simulink IO option in the chart properties dialog (see Specifying Chart Properties) is always on. This means that if input or output fixed-point data in Stateflow does not match its counterpart data in Simulink, a mismatch error results.
ml
Used for holding MATLAB data in Stateflow. See ml Data Type.

Fixed-Point

You select an integer base for the fixed-point data in the Stored Integer field. The scaling type for the fixed-point number is entered in the drop-down field below which can take one of the two selectable values, Fraction Length or Scaling. The scaling value is entered in the field to the right. For a detailed description of fixed-point data, see Fixed-Point Data.

Stored Integer.   Select the integer word type to hold the fixed-point data quantized integer. The size of the word in bits is indicated by a suffix of 8, 16, or 32. Larger word sizes can represent large quantities with greater precision than smaller word sizes. Unsigned types (uint8, uint16, uint32) can represent only positive quantities. Signed types (int8, int16, int32) can represent negative quantities.

Fraction length.   Select this value to interpret the entry in the adjacent field to the right as radix-point-only scaling. A positive integer entry moves the radix point left of the rightmost bit by that amount. For example, an entry of 2 sets the radix point in front of the second bit from the right. A negative integer entry moves the radix point further right of the rightmost bit by that amount. Only integers can be entered (see note below).

Scaling.   Select this value to interpret the entry in the adjacent field to the right as scaling with separate slope and bias entered in [Slope Bias] format (can be entered with or without brackets []). For example, the entry [2 3] sets the slope to 2 and the bias to 3. You can also enter the slope or bias as an arithmetic expression, for example, [1.2*2^-2 3.4]. If you enter a single value, it is interpreted as the slope. The value entered for the slope can be any positive real number. The value for the bias can be any real number. See following note.

Port

Index of the port associated with this data item (see Associating Ports with Data). This control applies only to input and output data.

Units

Units, for example, inches, centimeters, and so on, represented by this data item. The value of this field is stored with the item in the Stateflow machine's data dictionary.

Array

All data that you add is scalar in the specified Type (see preceding) by default. If you select the Array check box, this data item is an array. However, the Scope value that you assign this data limits the kind of array this data can be. See the following Sizes property.

When you select the Array check box, the Sizes and First Index fields are enabled in the Data dialog.

Sizes.   Size of this array. The value of this property can be a scalar or a MATLAB vector. If it is a scalar (for example, 5), it specifies the size of a one-dimensional array (that is, a vector). If it is a MATLAB vector (for example, '[2 3 7]'), it indicates the size of each dimension of a multidimensional array whose number of dimensions corresponds to the length of the vector.

The allowed size of the data array that you specify depends on the data's Scope property, as follows:

Scope
Scalar
Vector
Matrix
2-dim
Matrix
n-dim
Constant
Yes
No
No
No
Input from Simulink/Output to Simulink
Yes
Yes
Yes
No
Temporary/Local
Yes
Yes
Yes
Yes
Imported/Exported
Yes
Yes
Yes
Yes
Input (to function)/
Output (to function)
Yes
No
No
No

First Index.   Specifies the index of the first element of this array. For example, the first index of a zero-based array is 0.

Limit Range

This control group specifies values used by a Stateflow machine to check the validity of this data item. It includes the next two controls.

Min.   Minimum value that this data item can have during execution or simulation of the Stateflow machine it belongs to.

Max.   Maximum value that this data item can have during execution or simulation of the Stateflow machine it belongs to.

Initialize from

Source of the initial value for this data item: either the Stateflow data dictionary or the MATLAB workspace. If this data item is an array, Stateflow sets each element of the array to the specified initial value.

If the source is the data dictionary, enter the initial value in the adjacent text field. Stateflow stores the value that you enter in the data dictionary.

If the source is the MATLAB workspace, this item gets its initial value from a similarly named variable in the MATLAB workspace. For example, suppose that the name of a Stateflow data item is A. If the parent workspace has a variable named A, this value is used to initialize the data item.

The following table summarizes the time of initialization for each data scope.

Data Parent
Scope
When Initialized
Machine
Local
Exported
Imported
Start of simulation
Start of simulation
Not applicable
Chart
Input
Output
Local
Not applicable
Start of simulation or when chart is reinitialized as part of an enabled Simulink subsystem
State with History junction
Local
Start of simulation or when chart is reinitialized as part of an enabled Simulink subsystem
State without History junction
Local
State activation (state entered)
Graphical Function
Input
Output
Local
Not applicable
When function is invoked
Start of simulation or when chart is reinitialized as part of an enabled Simulink subsystem

Save final value to base workspace

Selecting this option causes the value of the data item to be assigned to a similarly named variable in the model's base workspace at the end of simulation.

Watch in debugger

If selected, this option causes the debugger to halt if this data item is modified.

Description

Description of this data item.

Document link

Stateflow allows you to provide online documentation for data defined by a model. To document a particular item of data, set this property to a MATLAB expression that displays documentation in some suitable online format (for example, an HTML file or text in the MATLAB Command Window). Stateflow evaluates the expression when you click the item's documentation link (the blue text that reads Document Link displayed at the bottom of the event's Data dialog box).


  Adding Data to the Data Dictionary Defining Data Arrays