Give control to keyboard
keyboard pauses execution of a running
program and gives control to the keyboard. Place the
in a program at the location where you want MATLAB® to pause.
When the program pauses, the prompt in the Command Window changes
K>>, indicating that MATLAB is in
debug mode. You then can view or change the values of variables to
see if the new values produce expected results.
keyboard function is useful for debugging
Modify Variables While Debugging
to pause execution of a program and modify a variable before continuing.
Create a file,
function z = buggy(x) n = length(x); keyboard z = (1:n)./x;
buggy.m. MATLAB pauses at
line 3, where the
keyboard command is located.
Multiply the variable
x by 2 and continue
running the program. MATLAB executes the rest of the program
using the new value of
x = x * 2 dbcont
Introduced before R2006a