A connective junction represents a decision point in a transition path. You can combine transitions and connective junctions to create paths from a common source to multiple destinations or from multiple sources to a common destination. For more information on the semantics of branching paths, see Represent Multiple Paths by Using Connective Junctions.
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 junction cue.
Alternatively, to add an isolated junction to a chart:
Open the Stateflow Editor.
From the object palette, click the Junction icon
and move the pointer to the chart canvas. A
connective junction appears.
To place the connective junction, click a location on the canvas.
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 — Textual description of the junction. You can enter a brief description and comments.
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.
By combining transitions and connective junctions, you can construct common transition patterns such as:
if-then-else
decision patterns
for
loop patterns
while
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 All Conditions SpecifiedIn this example, the state Checked_in
has a default transition path with three connective junctions. Each branch of the path is guarded by a condition.
If the state Front_desk
is active, the event check_in
triggers the execution of the default transition in Checked_in
. The outcome of the default transition depends on the value of room_type
:
If room_type
is 1, the substate Executive_suite
becomes active.
If room_type
is 2, the substate Family_suite
becomes active.
If room_type
is 3, the substate Single_room
becomes active.
If none of these conditions is true, the default transition path is not valid and Front_desk
remains active.
For more information about this chart, see How Stateflow Objects Interact During Execution.
If-then-else
Pattern with an Unconditional TransitionIn 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 state
Fast
becomes active.
If u
equals 1 between and
, the state
Good
becomes active.
If u
equals 1 after , the state
Slow
becomes active.
For more information about this chart, see Detect Elapsed Time.
For
Loop PatternIn 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 PatternIn 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; }