Stateflow® structures enable you to bundle data of different size and type together into a
single Simulink.Bus
object. Using dot notation and
numeric indices, you can access and modify the contents of a Stateflow structure. For more information, see Access Bus Signals Through Stateflow Structures.
To index substructures and fields of Stateflow structures, use dot notation. The first part of a name identifies the parent
object. Subsequent parts identify the children along a hierarchical path. When the parent is
a structure, its children are individual fields or fields that contain other structures
(also called substructures). The names of the fields of a Stateflow structure match the names of the elements of the
Simulink.Bus
object that defines the structure.
For example, the C chart in this model contains an input structure
in
, an output structure out
, and a local structure
subbus
.
Structure | Scope | Simulink.Bus Object |
---|---|---|
in | Input | BusObject |
out | Output | BusObject |
subbus | Local | SubBus |
The fields of the input structure in
and the output structure
out
have the same name as the elements of
Simulink.Bus
object BusObject
that defines them:
sb
, a
, b
, and
c
. The field of the local structure subbus
has the
same name ele
as the element of Simulink.Bus
object
SubBus
. This table lists how the Stateflow chart resolves symbols in dot notation for indexing the fields of these
structures.
Dot Notation | Symbol Resolution |
---|---|
in.c | Field c of input structure in |
out.sb | Substructure sb of output structure
out |
in.a[0] | First value of the vector field a of input structure
in |
subbus.ele[1][1] | Value in the second row, second column of field ele of local
structure subbus |
in.sb.ele[2][3] | Value in the third row, fourth column of field ele of
substructure in.sb |
In this example, the Stateflow chart uses brackets and zero-based indexing for vectors and arrays because C is the action language for the chart. For more information, see Differences Between MATLAB and C as Action Language Syntax.
You can assign values to any Stateflow structure, substructure, or a field of a structure with a scope different from
Input
.
To assign one structure to another structure, define both structures from the same
Simulink.Bus
object in the base workspace.
To assign one structure to a substructure of a different structure (or vice
versa), define the structure and substructure from the same
Simulink.Bus
object.
To assign a field of one structure to a field of another structure, the fields
must have the same type and size. You can define the Stateflow structures from different Simulink.Bus
objects.
This table presents valid and invalid structure assignments based on the structure specifications for the previous example.
Assignment | Valid or Invalid? | Explanation |
---|---|---|
| Invalid | You cannot write to input structures. |
| Valid | Both |
| Invalid | The structures |
| Invalid | You cannot write to substructures of input structures. |
| Valid | The substructure |
| Invalid | You cannot write to fields of input structures. |
| Valid | The field |
| Valid | The field |