MATLAB Programming Fundamentals - MathWorks

(やまだぃちぅ) #1
To examine values at increments in a for loop, set the breakpoint within the loop, rather
than at the start of the loop. If you set the breakpoint at the start of the for loop, and then
step through the file, MATLAB pauses at the for statement only once. However, if you
place the breakpoint within the loop, MATLAB pauses at each pass through the loop.

Conditional Breakpoints


A conditional breakpoint causes MATLAB to pause at a specified line in a file only when
the specified condition is met. Use conditional breakpoints when you want to examine
results after some iterations in a loop.

To set a conditional breakpoint, right-click the breakpoint alley at an executable line
where you want to set the breakpoint and select Set/Modify Condition.

When the Editor dialog box opens, enter a condition and click OK. A condition is any valid
MATLAB expression that returns a logical scalar value.

As noted in the dialog box, MATLAB evaluates the condition before running the line. For
example, suppose that you have a file called myprogram.m.

Add a breakpoint with the following condition at line 6:

n >= 4

A yellow, conditional breakpoint icon appears in the breakpoint alley at that line.

22 Debugging MATLAB Code

Free download pdf