The data tip stays in view until you move the pointer. If you have trouble getting the data
tip to appear, click the line containing the variable, and then move the pointer next to the
variable. For more information, see “Examine Values While Debugging” on page 22-15.
You can change the value of a variable while debugging to see if the new value produces
expected results. With the program paused, assign a new value to the variable in the
Command Window, Workspace browser, or Variables Editor. Then, continue running or
stepping through the program.
For example, here MATLAB is paused inside a for loop where n = 2:
- Type n = 7; in the command line to change the current value of n from 2 to 7.
Press Continue to run the next line of code.
MATLAB runs the code line x(n) = 2 * x(n-1); with n = 7.
Modify Section of Code While Debugging
You can modify a section of code while debugging to test possible fixes without having to
save your changes. Usually, it is a good practice to modify a MATLAB file after you quit
debugging, and then save the modification and run the file. Otherwise, you might get
unexpected results. However, there are situations where you want to experiment during
debugging.
To modify a program while debugging:
Debug a MATLAB Program