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:
Select the Stateflow library.
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 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:
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
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:
In the Modeling tab, under Design Data, select Property Inspector.
In the Stateflow Editor, click the state transition table.
In the Property Inspector, edit the state transition table properties.
To use the Model Explorer:
In the Modeling tab, under Design Data, select Model Explorer.
In the Model Hierarchy pane, select the state transition table.
In the Dialog pane, edit the state transition table properties.
To use the State Transition Table properties dialog box:
Open the Stateflow Editor.
In the Modeling tab, click Table Properties.
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.