Stateflow User's Guide Previous page   Next Page

Adding a History Junction to Save State

If a Stateflow diagram exits and reenters a superstate like the one in Simulating the Superstate, the destination substate of the default transition becomes the first active substate. While this behavior might be acceptable for some superstates, for others, it might be preferable to reenter the most recently active substate.

For example, suppose that a superstate represents the state of a clothes washer and its substates represent its different cycles: soak, wash, rinse, and spin. If you lift the lid of a washer while it is in the spin cycle, the washer stops in response. If you drop the lid, the washer resumes its spin cycle. If, instead, the soak cycle started again, it might take you a long time to get your clothes washed!

History junctions extend the ability of charts and superstates by recording the activity of their substates. You use a history junction in a chart or a superstate to indicate that its last active substate becomes active when the chart or superstate is reentered. Add and simulate the effects of a history junction in the following procedure topics:

  1. Adding a History Junction to a Superstate
  2. Simulating with a History Junction

Previous page  Simulating the Superstate Adding a History Junction to a Superstate Next page

© 1994-2005 The MathWorks, Inc.