Main Content

State Transition Tables in Stateflow

A state transition table is an alternative way of expressing sequential modal logic. Instead of drawing states and transitions graphically in a Stateflow® chart, use state transition tables to express the modal logic in tabular format. State transition tables are supported only as blocks in a Simulink® model.

The benefits of using state transition tables include:

  • The ease of modeling train-like state machines, where the modal logic involves transitions from one state to its neighbor

  • A concise, compact format for a state machine

  • Reduced maintenance of graphical objects

  • When you add or remove states from a chart, you have to rearrange states, transitions, and junctions. When you add or remove states from a state transition table, you do not have to rearrange any graphical objects.

State transition tables support using both MATLAB® and C as the action language. For more information about the differences between these action languages, see Differences Between MATLAB and C as Action Language Syntax.

Create a State Transition Table

At the MATLAB command prompt, enter:

  • To create a State Transition Table in a new Simulink model, enter:

    sfnew -STT
  • To add a new State Transition Table to an existing model, use the function add_block (Simulink). For example:

    add_block('sflib/State Transition Table','myModel/State Transition Table')

From the Simulink Library Browser:

  1. Select the Stateflow library.

  2. Drag a state transition table into your model.

Anatomy of a State Transition Table

A state transition table contains the following components:

Each transition column contains the following state-to-state transition information:

  • Condition

  • Condition action

  • Destination state

Use a State Transition Chart to Model a Boiler

The following state transition table contains the modal logic for maintaining the temperature of a boiler between two set points:

This Stateflow chart represents the same modal logic:

Differences Between State Transition Tables and Charts

State transition tables support a subset of the most commonly used elements in Stateflow charts. Elements that state transition tables do not support include:

  • Supertransitions

  • Parallel (AND) decomposition

  • Local events

  • Flow charts

  • Use of chart-level functions (graphical, truth table, MATLAB, and Simulink)

Guidelines for Using State Transition Tables

  • If you specify an action in a transition cell, it must be a condition action.

  • State transition tables must have at least one state row and one transition column.

Specify Properties for State Transition Tables

To open the State Transition Table properties dialog box, in the Modeling tab, click Table Properties.

The properties for state transition tables are the same as those for charts that use MATLAB as the action language. For a description of each property, see Specify Properties for Stateflow Charts.

You can also specify state transition table properties programmatically by using Stateflow.StateTransitionTableChart objects. For more information about the Stateflow programmatic interface, see Overview of the Stateflow API.

Generate Diagrams from State Transition Tables

Stateflow software automatically generates a read-only state transition diagram from the state transition table you create. As you enter changes to a state transition table, Stateflow incrementally updates the diagram as well. To see the most up-to-date version of the underlying diagram, in the Debug tab, click Show Auto Chart.

See Also

Related Topics