|On this page…|
You index substructures and fields of Stateflow® structures by using dot notation. With dot notation, the first text string identifies the parent object, and subsequent text strings 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). By default, the names of the fields of a Stateflow structure match the names of the elements of the Simulink.Bus object that defines the structure.
The following structures are defined in the chart:
|Name of Structure||Scope||Defined By Simulink.Bus Object|
The Simulink.Bus objects that define these structures have the following elements:
By default, Stateflow structures in and out have the same fields — sb, a, b, and c — as the elements of Simulink.Bus object BusObject. Similarly, the Stateflow structure subbus has the same field ele as the element of Simulink.Bus object SubBus. Based on these specifications, the following table shows how the Stateflow chart resolves symbols in dot notation for indexing fields of the structures in this example:
|Dot Notation||Symbol Resolution|
|in.c||Field c of input structure in|
|in.a||Second value of the vector field a of input structure in|
|out.sb||Substructure sb of output structure out|
|in.sb.ele||Value in the third row, fourth column of field ele of substructure sb of input structure in|
|subbus.ele||Value in the second row, second column of field ele of local structure subbus|
You can assign values to any Stateflow structure except input structures — that is, a structure with scope equal to Input. Here are the guidelines for assigning values to output, local, parameter, and temporary structures:
Assign one structure to another structure
You must define both structures with the same Simulink.Bus object in the base workspace.
Assign one structure to a substructure of a different structure and vice versa
You must define the structure with the same Simulink.Bus object in the base workspace as the substructure.
Assign a field of one structure to a field of another structure
The fields must have the same type and size.
For example, the following table presents valid and invalid structure assignments based on specifications for the sfbus_demosfbus_demo model, as described in Connect Structures in Charts to External Bus Signals:
|Assignment||Valid or Invalid?||Rationale|
outbus = inbus;
Both outbus and inbus are defined by the same Simulink.Bus object, COUNTERBUS.
inbus = outbus;
You cannot write to input structures.
inbus.limits = outbus.limits;
You cannot write to fields of input structures.
counterbus_struct = inbus;
Both counterbus_struct and inbus are defined by the same Simulink.Bus object, COUNTERBUS.
counterbus_struct.inputsignal = inbus.inputsignal;
Both counterbus_struct.inputsignal and inbus.inputsignal have the same type and size because they each reference field inputsignal, a substructure of the Simulink.Bus object COUNTERBUS.
outbus.limits.upper_saturation_limit = inbus.inputsignal.input;
The field upper_saturation_limit from limits, a substructure of COUNTERBUS, has the same type and size as the field input from inputsignal, a different substructure of COUNTERBUS.
outbus.limits = inbus.inputsignal;
The substructure limits is defined by a different Simulink.Bus object than the substructure inputsignal.
When you write custom functions that take structure pointers as arguments, you must pass the structures by address. To get addresses of Stateflow structures and structure fields, use the & operator, as in the following examples:
&in — Address of Stateflow structure in
&in.b — Address of field b in Stateflow structure in
... extern void counterbusFcn (COUNTERBUS *u1, int u2, COUNTERBUS *y1, int *y2); ...
To call this function, you must pass addresses to two structures defined by the Simulink.Bus object COUNTERBUS, as in this example:
counterbusFcn(&counterbus_struct, u2, &outbus, &y2);
See Connect Structures in Charts to External Bus Signals for a description of the structures defined in sfbus_demosfbus_demo.