| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → Stateflow |
| Contents | Index |
| Learn more about Stateflow |
Truth table functions implement logical decision-making behavior that you call in an action language. Stateflow truth tables contain conditions, decisions, and actions arranged as follows:
Condition | Decision 1 | Decision 2 | Decision 3 | Default Decision |
|---|---|---|---|---|
x == 1 | T | F | F | - |
y == 1 | F | T | F | - |
z == 1 | F | F | T | - |
Action | t = 1 | t = 2 | t = 3 | t = 4 |
Each of the conditions entered in the Condition column must evaluate to true (nonzero value) or false (zero value). Outcomes for each condition are specified as T (true), F (false), or - (true or false). Each of the decision columns combines an outcome for each condition with a logical AND into a compound condition, that is referred to as a decision.
You evaluate a truth table one decision at a time, starting with Decision 1. If one of the decisions is true, you perform its action and truth table execution is complete. For example, if conditions 1 and 2 are false and condition 3 is true, Decision 3 is true and the variable t is set equal to 3. The remaining decisions are not tested and evaluation of the truth table is finished.
The last decision in the preceding example, Default Decision, covers all possible remaining decisions. If Decisions 1, 2, and 3 are false, then the Default Decision is automatically true and its action (t = 4) is executed. You can see this behavior when you examine the following equivalent pseudocode for the evaluation of the preceding truth table example:
Description | Pseudocode |
|---|---|
Decision 1 Decision 1 Action | if ((x == 1) & !(y == 1) & !(z == 1)) t = 1; |
Decision 2 Decision 2 Action | elseif (!(x == 1) & (y == 1) !(z == 1)) t = 2; |
Decision 3 Decision 3 Action | elseif (!(x == 1) & !(y == 1) (z == 1)) t = 3; |
Default Decision Default Decision Action | else t = 4; endif |
![]() | Truth Table Functions | Language Options for Stateflow Truth Tables | ![]() |

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 |