Main Content

State Transition Tables in Stateflow

The State Transition Table block represents a finite state machine for sequential modal logic in tabular format. Instead of drawing states and transitions in a Stateflow® chart, you can use a state transition table to model a state machine in a concise, compact format that requires minimal maintenance of graphical objects.

To implement control logic, state transition tables can use MATLAB® or C as the action language. For more information, 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.

    Block icon for state transition table.

Anatomy of a State Transition Table

A state transition table contains the following components:

Diagram of state transition table highlighting state column, transition column, condition cell, condition action cell, and destination state cell.

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

  • Condition

  • Condition action

  • Destination state

Use a State Transition Table to Model a Boiler

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

State transition table with two top-level states called Normal and Alarm. Normal has three substates called Off, Warmup, and On.

This Stateflow chart represents the same modal logic:

Stateflow chart with two top-level states called Normal and Alarm. Normal has three substates called Off, Warmup, and On.

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

State transition table properties specify how your state transition table interfaces with the Simulink model. You can modify these properties in the Property Inspector, the Model Explorer, or the State Transition Table properties dialog box.

To use the Property Inspector:

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

  2. In the Stateflow Editor, click the state transition table.

  3. In the Property Inspector, edit the state transition table 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 state transition table.

  3. In the Dialog pane, edit the state transition table properties.

To use the State Transition Table properties dialog box:

  1. Open the Stateflow Editor.

  2. In the Modeling tab, click Table Properties.

  3. In the properties dialog box, edit the state transition table properties.

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

Tip

State transition table properties are a subset of the properties for Stateflow charts. For a description of each property, see Specify Properties for Stateflow Charts.

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

Blocks

Objects

Related Topics