Combine Transitions and Junctions to Create Branching Paths
A connective junction represents a decision point in a transition path. You can combine transitions and connective junctions to create paths from a single source to multiple destinations or from multiple sources to a single destination. For more information on the semantics of branching paths, see Represent Multiple Paths by Using Connective Junctions.
Add a Connective Junction
When you add a transition to a chart, the Stateflow® Editor provides graphical cues that allow you to add a junction or a state. To place a junction at the end of the transition, click the circular cue.
Alternatively, to add an isolated junction to a chart:
In the object palette, click the Junction icon .
On the chart canvas, click the location for the new connective junction.
Modify Connective Junction Properties
To change the size of one or more connective junctions:
Select the connective junctions.
Right-click one of the selected junctions and select Junction Size.
From the drop-down list, select a junction size.
To change other properties of a connective junction, right-click a connective junction and select Properties. The Connective Junction dialog box displays these properties:
Parent — Parent state of the connective junction. To bring the parent to the foreground, click the hypertext link. This property is read-only.
Description — Description of the junction.
Document link — Link to online documentation for the junction. 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.
Examples of Transition Paths with Connective Junctions
By combining transitions and connective junctions, you can construct common transition patterns such as:
if-then-else
decision patternsfor
loop patternswhile
loop patterns
To reduce the creation time of these patterns, use the Pattern Wizard. For more information, see Create Flow Charts by Using Pattern Wizard.
If-then-else
Pattern with an Unconditional Transition
In this example, the transition from state Start
has three connective junctions. The first two branches of the path are guarded by a condition. The last branch of the path is unconditional.
The chart uses temporal logic to determine when the input u
equals 1:
If
u
equals 1 before time , the stateFast
becomes active.If
u
equals 1 between and , the stateGood
becomes active.If
u
equals 1 after , the stateSlow
becomes active.
For more information about this chart, see Detect Elapsed Time.
For
Loop Pattern
In this example, a flow chart uses a combination of transitions and connective junctions to construct a for
loop.
As the value of the counter i
increases from 1 to 10, the flow chart defines the elements of an array output
. The loop in this flow chart is equivalent to this snippet of MATLAB code:
for i = 1:10 output(i) = 2*i; end
While
Loop Pattern
In this example, a flow chart combines transitions and connective junctions to construct a while
loop that computes the greatest common divisor of the inputs.
The loop in this flow chart is equivalent to this snippet of C code:
while(q > 0) { r = fmod(p,q); p = q; q = r; }
Specify Properties for Connective Junctions
You can modify the properties listed below in the Property Inspector, the Model Explorer, or the Connective Junction properties dialog box.
To use the Property Inspector:
In the Modeling tab, under Design Data, select Property Inspector.
In the Stateflow Editor, select the connective junction.
In the Property Inspector, edit the connective junction properties.
To use the Model Explorer:
In the Modeling tab, under Design Data, select Model Explorer.
In the Model Hierarchy pane, select the parent state or chart for the connective junction.
In the Contents pane, select the connective junction.
In the Dialog pane, edit the connective junction properties.
To use the Connective Junction properties dialog box:
In the Stateflow Editor, right-click the connective junction.
Select Properties.
In the properties dialog box, edit the connective junction properties.
You can also modify junction properties programmatically by using Stateflow.Junction
objects. For more information about the Stateflow programmatic interface, see Overview of the Stateflow API.
Parent
Parent of the connective junction. This property is read-only and is not available in the Property Inspector. When you click the parent hyperlink, the Stateflow Editor brings the parent to the foreground.
Description
Description of the connective junction.
Document link
Link to online documentation for the connective junction. 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 the Document link hyperlink, Stateflow evaluates the link and displays the documentation.
See Also
Objects
Tools
- Model Explorer (Simulink)