MATLAB Programming Fundamentals - MathWorks

(やまだぃちぅ) #1

Examine Values While Debugging


While your program is paused, you can view the value of any variable currently in the
workspace. Examine values when you want to see whether a line of code produces the
expected result or not. If the result is as expected, continue running or step to the next
line. If the result is not as you expect, then that line, or a previous line, might contain an
error.

Select Workspace


To examine a variable during debugging, you must first select its workspace. Variables
that you assign through the Command Window or create using scripts belong to the base
workspace. Variables that you create in a function belong to their own function
workspace. To view the current workspace, select the Editor tab. The Function Call
Stack field shows the current workspace. Alternatively, you can use the dbstack
function in the Command Window.

To select or change the workspace for the variable you want to view, use either of these
methods:


  • From the Editor tab, in the Debug section, choose a workspace from the Function
    Call Stack menu list.

  • From the Command Window, use the dbup and dbdown functions to select the
    previous or next workspace in the Function Call Stack.


To list the variables in the current workspace, use who or whos.

View Variable Value


There are several ways to view the value of a variable while debugging a program:


  • View variable values in the Workspace browser and Variables Editor.


The Workspace browser displays all variables in the current workspace. The Value
column of the Workspace browser shows the current value of the variable. To see more

Examine Values While Debugging
Free download pdf