Main Content

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.

New transition with graphical cues for adding a junction or state.

Alternatively, to add an isolated junction to a chart:

  1. In the object palette, click the Junction icon .

  2. 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:

  1. Select the connective junctions.

  2. Right-click one of the selected junctions and select Junction Size.

  3. 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 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 Specified

In 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 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 $t=2$, the state Fast becomes active.

  • If u equals 1 between $t=2$ and $t=5$, the state Good becomes active.

  • If u equals 1 after $t=5$, the state Slow 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 specify the properties listed below in the Property Inspector, the Model Explorer, or the Connective Junction properties dialog box.

To use the Property Inspector:

  1. In the Modeling tab, under Design Data, select Property Inspector.

  2. In the Stateflow Editor, select the connective junction.

  3. In the Property Inspector, edit the connective junction properties.

To use the Model Explorer:

  1. In the Modeling tab, under Design Data, select Model Explorer.

  2. In the Model Hierarchy pane, select the parent state or chart for the connective junction.

  3. In the Contents pane, select the connective junction.

  4. In the Dialog pane, edit the connective junction properties.

To use the Connective Junction properties dialog box:

  1. In the Stateflow Editor, right-click the connective junction.

  2. Select Properties.

  3. In the properties dialog box, edit the connective junction properties.

You can also specify 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

Related Topics