Desktop Tools and Development Environment Previous page   Next Page

Examining Values in the Example

Step from line 9 through line 13 in collatz. Step again, and the pause indicator jumps to line 17, just after the if loop, as expected. Step again, to line 18, check the value of sequence in line 17 and see that the array is

2  1

as expected for n = 2. Step again, which moves the pause indicator from line 18 to line 11. At line 11, step again. Because next_value is now 1, the while loop ends. The pause indicator is at line 11 and appears as a green down arrow . This indicates that processing in the called function is complete and program control will return to the calling program. Step again from line 11 in collatz and execution is now paused at line 10 in collatzplot.

Note that instead of stepping through collatz, the called function, as was just done in this example, you can step out from a called function back to the calling function, which automatically runs the rest of the called function and returns to the next line in the calling function. To step out, use the Step Out button or type dbstep out in the Command Window.

In collatzplot, step again to advance to line 11, then line 12. The variable seq_length in line 11 is a vector with the elements

1  2

which is correct.

Finally, step again to advance to line 13. Examining the values in line 12,
N  = 2 as expected, but the second variable, plot_seq, has two values, where only one value is expected. While the value for plot_seq is as expected

2  1

it is the incorrect variable for plotting. Instead, seq_length(N) should be plotted.


Previous page  Viewing Values in the Command Window Correcting Problems and Ending Debugging Next page

© 1994-2005 The MathWorks, Inc.