| Products & Services | Industries | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → Stateflow |
| Contents | Index |
| Learn more about Stateflow |
| On this page… |
|---|
How Stateflow Software Generates Graphical Functions for Truth Tables How Stateflow Software Generates Embedded MATLAB Code for Truth Tables |
Stateflow software realizes the logical behavior specified in a truth table by generating content as follows:
| Type of Truth Table | Generated Content |
|---|---|
| Stateflow Classic | Graphical function |
| Embedded MATLAB | Embedded MATLAB code |
You generate content for a truth table when you simulate your model. Content regenerates whenever a truth table changes. To view the generated content of a truth table, follow these steps:
Simulate the model that contains the truth table.
Double-click the truth table to open its editor.
Select the View Generated Content
button.
This section describes how Stateflow software translates the logic of a Stateflow Classic truth table into a graphical function.
In this example, a Stateflow Classic truth table has three conditions, four decisions and actions, and initial and final actions.

Stateflow software generates a graphical function for the preceding truth table. The top half of the flow graph is as follows, where the numbered steps show the order of execution.

The top half of the flow graph executes as follows:
Performs initial actions
Evaluates the conditions and stores the results in temporary data variables
The temporary data for storing conditions is based on the labels that you enter for the conditions. If you do not specify the labels, temporary data variables appear.
The bottom half of the flow graph is as follows, where the numbered steps show the order of execution for each condition and action.

In the bottom half of the flow graph, the stored values for conditions determine which decision is true and what action to perform. Each decision appears as a fork from a connective junction with one of two possible paths:
A transition segment with a decision followed by a segment with the consequent action
The action appears as a condition action that leads to the FINAL action and termination of the flow graph.
A transition segment that flows to the next fork for an evaluation of the next decision
This transition segment has no condition or action.
This implementation continues from the first decision through the remaining decisions in left-to-right column order. When a decision match occurs, the action for that decision executes as a condition action of its transition segment. After the action executes, the flow graph performs the final action for the truth table and terminates. Therefore, only one action results from a call to a truth table graphical function. This behavior also means that no data dependencies are possible between different decisions.
Stateflow software generates the content of Embedded MATLAB truth tables as Embedded MATLAB code that represents each action as a nested function inside the main truth table function.
Nested functions offer these advantages over subfunctions:
Nested functions are independent of each other. Therefore, variables are local to each function and not subject to naming conflicts.
Nested functions can access all data from the main truth table function.
The generated content appears in the Embedded MATLAB Editor, which provides tools for simulation and debugging, as described in Debugging an Embedded MATLAB Function Block.
Here is the generated content for the Embedded MATLAB truth table described in Programming Actions in Embedded MATLAB Action Language:
Main truth table function

Action A1

Actions A2, A3, and A4

![]() | Checking Model Coverage for Truth Tables | Truth Table Editor Operations | ![]() |

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |