Use State Transition Tables to Express Sequential Logic in Tabular Form
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.
In a state transition table, rows represent the states in your system. The transition columns specify the condition, condition action, and destination state for each outgoing transition from a state.
For example, this state transition table contains the modal logic for maintaining the
temperature of a boiler between two set points,
reference_high. During normal operation, the boiler cycles
between the states
The state transition table represents the same modal logic as this Stateflow chart.
For more information about this example, see Model Bang-Bang Controller by Using a State Transition Table.
Program a State Transition Table
To create a State Transition Table:
Create a Simulink® model that contains a State Transition Table block by calling the function
Double-click the State Transition Table block.
For each operating mode in your system, add a state row and enter a state label, as described in Define Actions in a State. To organize complex systems, define a hierarchy of states by adding child state rows below a parent state row.
To add a state row, select an existing state and, in the Modeling tab, choose from one of these options:
Insert State Row — Add a state at the same level of hierarchy.
Insert Child State Row — Add a state as a child of the selected state.
To move a state row, click the top edge of the state and drag the state to a new location. As you drag the state, the editor displays a graphical cue that indicates the new position of the state.
To model operating modes that are active at the same time, enable parallel (AND) decomposition in a parent state. For more information, see Simulate Parallel States with a State Transition Table.
To represent the direction of flow logic between states, specify conditions, condition actions, and destinations for the outgoing transitions from each state.
To add a transition column, right-click the header for an existing column and choose from one of these options:
Append transition column — Add a transition column to the right of the table.
Insert transition column — Add a transition column to the left of the selected column.
To move the condition, action, and destination cells for a transition, click the top edge of the condition cell and drag the transition left or right. The condition, action, and destination cells move together as a single unit.
To specify the destination of the transition, in the destination state cell, select the name of a state or one of these options:
$NEXT— Create a transition to the next sibling state. This option is not available for the last substate in each level of the state hierarchy.
$PREV— Create a transition to the previous sibling state. This option is not available for the first substate in each level of the state hierarchy.
$SELF— Create a self-loop transition.
To comment out a transition, in the destination state cell, select
% IGNORE %.
At each level of the hierarchy, mark the first state to become active when the parent becomes active. Select a state and, in the Modeling tab, select Set as Default State.
Alternatively, to specify a default transition path with multiple branching points, in the Modeling tab, select Insert Default Transition Row. For example, this default transition row selects between two destinations,
A2, depending on the value of
To specify an inner transition from the a parent state to one or more child states, in the Modeling tab, select Insert Inner Transition Row. For example, in this inner transition row, the input event
Etriggers an inner transition that selects between two destinations,
B2, depending on the values of
You must specify destination states in an inner transition row in the same order that the corresponding child states appear in the table. For instance, in the previous example, state
B1must appear above state
If your system has inputs or outputs, or depends on any state variables, add input, output, and local data as described in Add Stateflow Data.
If your system reacts to event triggers or must trigger actions in your chart or other blocks in your model, add input and output events, as described in Synchronize Model Components by Broadcasting Events.
Connect the State Transition Table block to other blocks in the Simulink model by using input and output ports.
To simulate the model, click Run. During the simulation, the state transition table highlights the active states and transitions.
Simulate Parallel States with a State Transition Table
In Stateflow, the substates of states that use parallel decomposition are
active simultaneously. For example, if State A uses parallel decomposition and
has two substates,
A2 are active at the same time.
For more information on parallel states, see Define Exclusive and Parallel Modes by Using State Decomposition.
To use parallel states in State Transition Table blocks, enter the state transition table. To change the decomposition at the chart level, enter the state transition table, but do not select a state. In the Modeling tab, select Decomposition > Parallel (AND). To give a state parallel decomposition, select the state whose decomposition you want to change. In the Modeling tab, select Decomposition > Parallel (AND).
Before updating the decomposition of your chart or state to Parallel (AND), all cells in the transition column of the state must be clear.
Parallel states have a dashed outline that indicates that they are active simultaneously.
Detect Errors in State Transition Tables
To run diagnostic checks on a state transition table, in the Debug tab, select Update Model > Update Table. The diagnostics tool statically parses the table to find errors such as:
Default transition rows without an unconditional transition
Transition cells with conditions or actions, but no destination
Action text in a condition cell
Inner transition rows that specify destination states in a different order than the corresponding states appear in the table
These error checks are also performed during simulation. For more information about debugging state transition tables, see Debug Run-Time Errors in a State Transition Table.
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:
Open the State Transition Table block.
In the Modeling tab, under Design Data, select Property Inspector.
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 State Transition Table block.
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.
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.
Guidelines for Using State Transition Tables
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.
State transition tables must have at least one state row and one transition column.
State transition tables do not support these elements of Stateflow charts:
Chart-level graphical, truth table, MATLAB, and Simulink functions