Stateflow User's Guide Previous page   Next Page

What Is a Truth Table?

Stateflow uses truth table functions to realize logical decision-making behavior that you call in action language. Stateflow truth tables contain conditions, decisions, and actions arranged like the following:

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
    


Previous page  Truth Table Functions Building a Simulink Model with a Stateflow Truth Table Next page

© 1994-2005 The MathWorks, Inc.