MATLAB Programming Fundamentals - MathWorks

(やまだぃちぅ) #1

If an executable statement spans multiple lines, you can set a breakpoint at each line in
that statement, even though the additional lines do not have a — (dash) in the breakpoint
alley. For example, in this code. you can set a breakpoint at all four lines:


For more information on the different types of breakpoints, see “Set Breakpoints” on page
22-8.


Run File


After setting breakpoints, run the file from the Command Window or the Editor. Running
the file produces these results:



  • The Run button changes to a Pause button.

  • The prompt in the Command Window changes to K>> indicating that MATLAB is in
    debug mode and that the keyboard is in control.

  • MATLAB pauses at the first breakpoint in the program. In the Editor, a green arrow
    just to the right of the breakpoint indicates the pause. The program does not execute
    the line where the pause occurs until it resumes running. For example, here the
    debugger pauses before the program executes x = ones(1,10);.

  • MATLAB displays the current workspace in the Function Call Stack, on the Editor
    tab in the Debug section.


If you use debugging functions from the Command Window, use dbstack to view the
Function Call Stack.

Debug a MATLAB Program
Free download pdf