主要内容

在真相表中调试错误

完全指定真实表后,开始调试它们的过程。第一步是运行诊断以检查用于语法错误的真实表,包括过度分配和下标,如所描述的纠正过度透明和欠指定的真实表。此外,您可以在模拟期间将断点直接添加到您的真相表中以调试。

独立状态流不支持真值表金宝app®charts in MATLAB®。For more information, see使用真理表来模拟组合逻辑

Find Syntax Errors by Running Diagnostics

To check for syntax errors:

  1. 双击真相表。

  2. In the truth table, clickRun Diagnostics

    例如,如果您改变行动的决定columnD4to an action that does not exist, you get an error message in the Diagnostic Viewer.

Truth table diagnostics run automatically when you simulate a model with a new or modified truth table. If no errors exist, the diagnostic window does not appear and simulation starts immediately.

Debug Logic by Using Breakpoints

You can use breakpoints in a Stateflow truth table to pause simulation and debug your logic. Once a breakpoint causes the simulation to pause, you can step through the actions and examine the data values at that specific point in the simulation.

使用真值表,您可以设置这些不同的断点类型:

  • Condition tested

  • Decision tested

  • Decision valid

  • 执行的行动

在仿真停止在断点时,您可以在Matlab命令提示符处继续在状态溢编辑器工具栏上执行图表,或通过选择键盘快捷键。

Toolbar Icon 选项 Command Description 键盘快捷方式

Continue dbcont

Continue the simulation to the next breakpoint.

Ctrl + T.

step dbstep

前进到真相执行中的下一步。

F10

Step In dbstep in

From a state or transition action that calls a function, advance to the first executable statement in the function.

From a statement in a function containing another function call, advance to the first executable statement in the second function.

Otherwise, advance to the next step in the truth table execution. (See Step Over.)

F11

Step Out dbstep out.

From a function call, return to the statement calling the function.

Otherwise, continue simulation to the next breakpoint. (See Continue.)

Shift+F11

Step Forward

Exit debug mode and pause simulation before next time step.

Stop dbquit.

退出调试模式并停止模拟。

Ctrl + Shift + T

Condition Breakpoints

To set a breakpoint when a condition is tested, right-click the condition cell and select设置断点(条件测试)。A red badge appears on the far left of the table next to the number of the condition. When you run the model, the simulation pauses when the condition is tested. Stateflow highlights the condition row being tested. Place your cursor over the data in the truth table to see its current value.

决策断点

To set a breakpoint when a decision is tested, right-click the top of the decision column and selectSet Breakpoint (Decision Tested)。决策栏旁边的红色徽章出现在决定的数量旁边。运行该模型时,在测试决定时,模拟暂停。StateFlow突出显示正在测试的决策列。将光标放在真实表中的数据上,以查看其当前值。

要在决策有效时设置断点,请右键单击决策列底部的操作单元格并选择设置断点(决定有效)。A red badge appears on the top of the cell next to the action number. When you run the model, the simulation pauses when the action is valid. Stateflow highlights the valid decision. Place your cursor over the data in the truth table to see its current value.

如果在决策有效时需要多个操作,则会为第一个可执行文件设置断点。

行动断点

To set a breakpoint when an action is executed, right-click the action cell and selectSet Breakpoint (Action Executed)。A red badge appears on the far left of the table next to the number of the action. When you run the model, the simulation pauses when the action is executed. Stateflow highlights the action row being tested. Place your cursor over the data in the truth table to see its current value.

If there is more than one action within the action cell, the breakpoint is set for the first action.

编辑断点

Click the breakpoint to open theEdit Breakpointdialog box. From this window you can disable the breakpoint by clearing theEnable Breakpointcheck box.

When you add a condition to a breakpoint, the breakpoint pauses the simulation only when its associated condition is真的

相关话题