m = 2 as expected, but the second variable, plot_seq, has two values, where only one value is expected...

Linki


» Dzieci to nie książeczki do kolorowania. Nie da się wypełnić ich naszymi ulubionymi kolorami.
»
enum Color { Red, Green, Blue, Max = Blue, } shows an enum that has two enum members – Blue and Max – that have the same...
»
What really sets Family Guy apart from The Simpsons is the portrayal of the two remaining family members...
»
To get started, declare the two widgets you need, a label to hold the Hello World text and a button to exit the application: private System...
»
to a few MHz) are caused by the chopping technique used by variable-speed drives or the electronic ballasts of fluorescent lighting...
»
NOT (!), 131 of variables, 217 operators, 127, 360 limits, implementation, 506 OR, 133 LIMITS...
»
values of the input parameters from the calling program...
»
But Che was already reconsidering...
»
STRING VARIABLE CPEB 15 DS; STRING VARIABLE CPART1 15 DS; ...
»
Rozdział 40Podczas śniadania głównym tematem rozmów była Brazylia i wszyscy starali się patrzeć z jak najlepszej strony na projekt Angela związany z...
»
- Opowiadaj dalej, Nelly - rzekłem...

Dzieci to nie książeczki do kolorowania. Nie da się wypełnić ich naszymi ulubionymi kolorami.

While plot_seq has the value expected, 2 1, it is
the incorrect variable for plotting. Instead, the variable seq_length should be
plotted.
Correcting Problems and Ending Debugging
These are some of the ways to correct problems and end the debugging session:
• “Changing Values and Checking Results” on page 7-29
• “Ending Debugging” on page 7-30
• “Clearing Breakpoints” on page 7-30
• “Correcting an M-File” on page 7-31
Many of these features are used in “Completing the Example” on page 7-31.
Changing Values and Checking Results. While debugging, you can change the value
of a variable in the current workspace to see if the new value produces expected
results. While the program is paused, assign a new value to the variable in the
Command Window or in the Array Editor. Then continue running or stepping
through the program. If the new value does not produce the expected results,
the program has a different or another problem.
7-29
7 Editing and Debugging M-Files
Ending Debugging. After identifying a problem, end the debugging session. You
must end a debugging session if you want to change an M-file to correct a
problem or if you want to run other functions in MATLAB.
Note Always quit debug mode before editing an M-file. If you edit an M-file
while in debug mode, you can get unexpected results when you run the file.
To end debugging, click the exit debug mode icon
, or select Exit Debug
Mode from the Debug menu.
You can instead use the function dbquit to end debugging.
After quitting debugging, the pause indicators in the Editor/Debugger display
no longer appear, and the normal prompt >> now appears in the Command
Window instead of the debugging prompt, K>>. You can no longer access the call
stack.
Clearing Breakpoints. Breakpoints remain in a file until you clear them. Clear the
breakpoints if you want the program to run uninterrupted, such as after
identifying and correcting a problem.
To clear a breakpoint in the Editor/Debugger, click on the breakpoint icon for
a line, or select Set/Clear Breakpoint from the Breakpoints or context menu.
The breakpoint for that line is cleared.
To clear all breakpoints in all files, select Clear All Breakpoints from the
Breakpoints menu, or click the
equivalent button on the toolbar.
The function that clears breakpoints is dbclear. To clear all breakpoints, use
dbclear all. For the example, clear all of the breakpoints in collatzplot by
typing
dbclear all in collatzplot
7-30
Debugging M-Files
Breakpoints are automatically cleared when you:
• End the MATLAB session
• Clear the M-file using clear name or clear all
• Edit the file if the changes impact line numbering
• Edit the file while in debug mode (although this does not always clear
breakpoints)
Correcting an M-File. To correct a problem in an M-file:
1 Quit debugging.
Do not make changes to an M-file while MATLAB is in debug mode. It could
produce unexpected debugging results when you run the M-file.
2 Clear all the breakpoints in the file.
The breakpoints become unreliable once the M-file is edited. The
breakpoints will produce unexpected debugging results when you run the
file.
3 Make changes to the M-file.
4 Save the M-file.
5 Set breakpoints, if desired.
6 Run the M-file again to be sure it produces the expected results.
Completing the Example. To correct the problem in the example, do the following:
1 End the debugging session. One way to do this is to select Exit Debug Mode
from the Debug menu.
2 Clear the breakpoints in collatzplot.m. One way to do this is by typing
dbclear all in collatzplot
in the Command Window.
7-31
7 Editing and Debugging M-Files
3 In collatzplot.m line 12, change the string plot_seq to seq_length(m) and
save the file.
4 Run collatzplot for n = 3 by typing
collatzplot(3)
in the Command Window.
5 Verify the result. The figure shows that the length of the Collatz series is 1
when n = 1, 2 when n = 2, and 8 when n = 3, as expected.
7-32
Debugging M-Files
6 Test the function for a slightly larger value of n, such as 6, to be sure the
results are still accurate. To make it easier to verify collatzplot for n = 6
as well as the results for collatz, add this line at the end of collatz.m
sequence
which displays the series in the Command Window.
Then run collatzplot for n = 6 by typing
collatzplot(6)
7-33
7 Editing and Debugging M-Files
7 To make debugging easier, you ran collatzplot for a small value of n. Now
that you know it works correctly, run collatzplot for a larger value to
produce more interesting results. Before doing so, you might want to
suppress output for the line you just added in step 6, line 18 of collatz.m,
by adding a semicolon to the end of the line so it appears as
sequence;
Then run
collatzplot(500)
The following figure shows the lengths of the Collatz series for n = 1 through
n = 500.
7-34
Preferences for the Editor/Debugger
Preferences for the Editor/Debugger
Using preferences, you can specify the default behavior for various aspects of
the Editor/Debugger.
To set preferences for the Editor/Debugger, select Preferences from the File
menu in the Editor/Debugger. The Preferences dialog box opens showing
Editor/Debugger Preferences.
7-35
7 Editing and Debugging M-Files
You can specify the following Editor/Debugger preferences:
• “General Preferences for the Editor/Debugger” on page 7-36 (on the first
panel, including the Editor preference)
• “Font & Colors Preferences for the Editor/Debugger” on page 7-37
• “Display Preferences for the Editor/Debugger” on page 7-38
• “Keyboard and Indenting Preferences for the Editor/Debugger” on page 7-40
• “Printing Preferences for the Editor/Debugger” on page 7-42
General Preferences for the Editor/Debugger
When you first access preferences for the Editor/Debugger, you can specify the
general preferences described here.
Editor

Powered by MyScript