Main Content

Create Entry and Exit Connections Across State Boundaries

Entry and exit ports represent connections into and out of states and subcharts. Like supertransitions, entry and exit ports create transition paths across boundaries in the Stateflow® hierarchy. However, because entry and exit ports isolate the transition logic for entering and exiting states, they can be used in atomic subcharts. Entry and exit ports are not supported in standalone Stateflow charts in MATLAB®.

In the Stateflow Editor, entry and exit ports appear as arrows on the boundary of a state or subchart. Each port has a matching junction that marks the entry or exit point inside the state or subchart. The entry junction icon and the exit junction icon indicate the junction. A transition path that leads to an entry port continues along the transition connected to the matching entry junction. Similarly, a transition path that leads to an exit junction continues along the transition connected to the matching exit port. For example, in this chart, the exit port labeled turnOff represents the exit connection out of the subchart On.

Chart with two states, On and Off. The label turnOff marks the exit port connected to a transition from On to Off.

In the subchart, the transition path leading to the exit junction defines the logic for exiting the subchart. In this example, the function warm must evaluate to true on two consecutive time steps before the chart makes the transition out of the On state.

Subchart containing an exit junction.

For more information about this example, see Model Bang-Bang Temperature Control System. For other examples that use entry and exit ports, see Isolate the Transition Logic for Entering and Exiting an Atomic Subchart and Model a Launch Abort System.

Add Entry and Exit Ports

To create an entry or exit port, add an entry or exit junction inside a state or subchart.

  1. In the object palette, click the Entry icon or the Exit icon .

  2. On the chart canvas, click the location for the new entry or exit junction. A matching entry or exit port appears on the boundary of the state or subchart that contains the new entry or exit junction.

  3. Enter a label for the junction and matching port. See Add Labels to Identify Matching Junctions and Ports.

Guidelines for Using Entry and Exit Ports

Add Entry and Exit Junctions Only to Exclusive (OR) States and Atomic Subcharts

Entry and exit junctions are supported only in exclusive (OR) states and atomic subcharts. Do not add entry or exit junctions to top level charts, parallel (AND) states, or boxes.

Add Labels to Identify Matching Junctions and Ports

Labels on entry and exit ports indicate which junction connects to which port. Adding a label is optional when a state contains only one entry or exit junction. Unique labels are required when a state contains more than one entry junction or more than one exit junction.

Prevent Backtracking Through Entry and Exit Ports

To ensure that the chart successfully enters or exits a state without backtracking, each entry junction and exit port must have a path that is not guarded by a condition or triggered by an event. Transition paths from entry junctions and exit ports must lead to states and must not contain terminal junctions.

Isolate the Transition Logic for Entry and Exit Junctions

Transition paths that start at entry junctions or end at exit junctions must be contained in the parent state.

Do Not Enter and Exit States in the Same Time Step

Default and inner transition paths must not connect to an exit junction.

Decide Between Supertransitions and Entry and Exit Ports

Both supertransitions and entry and exit ports enable you to move across different levels in the chart hierarchy. Which approach you select depends on your design requirements.

ScenarioRecommendation
Transition between the substates of two sibling states, neither of which is a subchartUse a supertransition. You can create a supertransition that does not cross any subchart boundaries by simply clicking the boundary of the source state and dragging your pointer to the destination state.
Transition to or from a substate of a normal subchart

Use either a supertransition or an entry or exit port.

  • If you use a supertransition, the points where each segment of the supertransition enters or exits different levels of the hierarchy affect one another. For example, moving the point where the supertransition enters the boundary of the subchart also moves the point where the supertransition exits the boundary of the subchart.

  • If you use an entry or exit port, the positions of the port and the matching junction are graphically independent of one another. For example, you can move the port without moving the junction.

Transition to or from a substate of an atomic subchartUse an entry or exit port. Supertransitions cannot cross the boundary of atomic subcharts.

Related Topics