Enter a Chart or State
Chart and state entry occurs when:
A chart is activated for the first time. This is called chart initialization.
A valid transition into a state exists. See Evaluate Transitions.
Workflow for Entering a Chart or State
This flow chart shows the progression of events that Stateflow® takes for entry into a chart or a state. In this flow chart, the current state refers to the state in which a decision or a process is taking place.

Chart Entry
The first time that your Stateflow chart becomes active is called initialization. When initialization of your chart occurs, the chart is entered and Stateflow executes any default transitions for exclusive (OR) states. If the states at the top level of your chart are parallel (AND), they become active based on their order number.
If you want your chart to take any default transitions before time t =
0, in the Chart Properties dialog box, select the Execute (enter)
chart at initialization check box. This option causes the Stateflow chart to initialize at the same time as Simulink® initialization. The default transition paths of the chart then execute
during the model initialization phase.
State Entry
When a state is marked for entry, entry actions for a state execute. Once your chart is active and has gone through initialization, the top-level state becomes active. A state is marked for entry in one of these ways:
An incoming transition crosses state boundaries.
An incoming transition ends at the state boundary.
The state is a parallel state child of an active state.
Entry Actions
Entry actions are preceded by the prefix entry or
en for short, followed by a required colon (:),
and then followed by one or more actions. You separate multiple actions by using a
carriage return, a semicolon (;), or a comma (,). If you do not specify the state action type explicitly
for a statement, the chart treats that statement as an
entry,during action.
Enter a Stateflow Chart
In this example, the first time the chart becomes active, chart initialization occurs.

By following the Workflow for Entering a Chart or State until the chart goes to sleep, the steps for chart initialization are in this order:
The default transition actions are executed, and
x = 0,y = 0, andz = 0.StateAis marked for entry.StateAis not a substate of an inactive parent. Perform theentryactions forStateA. Nowx = 1.StateAis the state that was initially marked for entry.StateAdoes not contain any history junctions.There is a default transition to the substate,
StateA1. Go to the Evaluate Transitions flow chart.By following the Evaluate Transitions flow chart, mark
StateA1forentry. Go to the Exit Actions flow chart.The current state,
StateA, is a superstate of the destination state,StateA1. Return to the Entry Actions flow chart.StateA1is not a substate of an inactive parent. Performentryactions forStateA1. Nowx = 3.StateA1is the state that was initially marked for entry.StateA1does not contain any history junctions.StateA1does not contain any default transitions.StateA1does not contain any single substates.The chart goes to sleep.
Steps 1 through 14 take place in the initial time step. This completes the chart initialization process.
Entering a State by Using History Junctions
If you want your Stateflow chart to remember and return to a substate that was previously active, regardless of a default transition, use a history junction. Placing a history junction within a state overrides the default transition leading to exclusive (OR) substates. After placing a history junction within a state, upon entry, your Stateflow chart remembers and enters the previously active substate. The history junction applies only to the level of the hierarchy in which it appears.
In this example, a light can be on or off. These options are indicated by the states
Power_on and Power_off. The options are
controlled by the input events switch_on and
switch_off. When the light is on, it can be dim or bright. These
options are indicated by the states Low and High
and are controlled by the input events switch_low and
switch_high.
Initially, the chart is asleep. The state Power_off is active.
When the state Power_on was last active, High was
the previously active substate. The event switch_on occurs and the
state Power_on is marked for entry. At this time p =
0.

By following the Workflow for Entering a Chart or State until the chart
goes to sleep, the execution steps for entering the state Power_on
are in this order:
Power_onis not the child of an inactive parent.There are no entry actions for
Power_on.Power_onis the state that was initially marked for entry.There are history junctions in
Power_on.Highwas the previously active substate. Nowp = 2.Highdoes not contain any history junctions.Highdoes not contain any default transitions.Highdoes not contain any single substates.The chart goes to sleep.
This completes the entry actions for Power_on
and High.
Entering a State by Using Supertransitions
A supertransition is a transition between different levels in a chart. A supertransition can be between a state in a top-level chart and a state in one of its subcharts, or between states residing in different subcharts at the same or different levels in a chart. You can create supertransitions that span any number of levels in your chart.
When a state is entered through a supertransition, before the entry actions for the
final destination are executed, its superstates must be marked active and their entry
actions must be executed. In this example, StateB1 has been marked
for entry from StateA2. At this point, x = 5,
y = 5, and z = 1.

By following the Workflow for Entering a Chart or State until the chart
goes to sleep, the execution steps for entering the state StateB1 are
in this order:
StateB1is the substate of an inactive parent (StateB).StateBis marked as active.StateBis not the substate of an inactive parent.Perform the entry actions for
StateB. Nowx = 4.StateBis not the state that was initially marked for entry.Perform the entry actions for
StateB1. Nowx = 3.StateB1is the state that was initially marked for entry.StateB1has no history junctions.StateB1does not contain any default transitions.StateB1does not contain any single substates.The chart goes to sleep.
This completes the entry actions for StateB and
StateB1.