Once you completely specify your truth tables, you begin the process of debugging them. The first step is to run diagnostics to check truth tables for syntax errors including overspecification and underspecification, as described in Correct Overspecified and Underspecified Truth Tables.
To check for syntax errors:
Double-click the truth table.
In the truth table, select Settings > Run Diagnostics.
For example, if you change the action for decision column D4 to an action that does not exist, you get an error message in the Diagnostic Viewer.
Truth table diagnostics run automatically when you start simulation of the model with a new or modified truth table. If no errors exist, the diagnostic window does not appear and simulation starts immediately.
Ways to debug truth tables during simulation include:
|Method||Type of Truth Tables||How To Do It|
|Use Stateflow® debugging tools to step through each condition and action, and monitor data values during simulation.||C truth table||See Use Stateflow Debugging Tools.|
|Use MATLAB® debugging tools to step through generated code for the truth table.||MATLAB truth table||See Use MATLAB Debugging Tools.|
When you use Stateflow debugging tools to debug truth tables, you must perform these tasks:
Specify a Breakpoint for the Call to a Truth Table. Before you debug the truth table during simulation, you must set a breakpoint for the truth table. This breakpoint pauses execution during simulation so that you can debug each execution step of a truth table.
In the chart, right-click the function box for the truth table.
Select Set Breakpoint During Function Call.
A breakpoint occurs when the chart calls this truth table function during simulation.
Step Through Conditions and Actions of a Truth Table. After setting a breakpoint for the truth table function call, you can step through conditions and actions:
Begin simulation of your model.
Wait until the breakpoint for the call to the truth table occurs. Stateflow generates the graphical function for the truth table.
Add truth table data to the Watch Data tab of the Stateflow Breakpoints and Watch window. From the Model Explorer, select each data. On the Data Properties dialog box. select Add to watch window.
Click Step In, , twice to advance simulation through the call to the truth table.
INIT action of the truth table highlights prior to
Click Step In to execute the
INIT action and advance truth
table execution to the first condition.
Click Step In to evaluate the first condition and advance truth table execution to the second condition.
Click Step In to evaluate the second condition and advance truth table execution to the third condition.
Click Step In to evaluate the third condition and advance truth table execution to the first decision.
Click Step In twice.
Because the first decision is true, truth table execution advances to its action
Click Step In four times to execute action
A1 and advance to
Click Step In.
This step executes the final action and exits the truth table. The Display block in the model displays the number 1.
MATLAB truth tables generate content as MATLAB code, a format that offers advantages for debugging. You can set breakpoints on any line of generated code (whereas you cannot set breakpoints directly on a truth table). You can debug code that MATLAB truth tables generate the same way you debug a MATLAB function.
For more information about how to generate content for truth tables, see How Stateflow Generates Content for Truth Tables