Desktop Tools and Development Environment |
Examining Values
While the 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 has produced 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 expected, then that line, or a previous line, contains an error. Use the following methods to examine values:
Many of these methods are used in Examining Values in the Example.
Selecting the Workspace
Variables assigned through the Command Window and created using scripts are considered to be in the base workspace. Variables created in a function belong to their own function workspace. To examine a variable, you must first select its workspace. When you run a program, the current workspace is shown in the Stack field. To examine values that are part of another workspace for a currently running function or for the base workspace, first select that workspace from the list in the Stack field.
If you use debugging functions from the Command Window, use dbstack
to display the call stack. Use dbup
and dbdown
to change to a different workspace. Use who
or whos
to list the variables in the current workspace.
Workspace in the Example. At line 10 of collatzplot
, we stepped in, putting us at line 9 of collatz
. The Stack shows that collatz
is the current workspace.
Stepping Through an M-File | Viewing Values as Datatips in the Editor/Debugger |
© 1994-2005 The MathWorks, Inc.