Main Content

keyboard

Give control to keyboard

Syntax

Description

example

keyboard pauses execution of a running program and gives control to the keyboard. Place the keyboard function in a program at the location where you want MATLAB® to pause. When the program pauses, the prompt in the Command Window changes to 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.

The keyboard function is useful for debugging your functions.

Examples

collapse all

Use the keyboard command to pause execution of a program and modify a variable before continuing.

Create a file, buggy.m, containing these statements.

function z = buggy(x)
n = length(x);
keyboard
z = (1:n)./x;

Run buggy.m. MATLAB pauses at line 3, where the keyboard command is located.

buggy(5)

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 = x * 2
dbcont

Tips

  • To terminate debug mode and continue execution, use the dbcont command.

  • To terminate debug mode and exit the file without completing execution, use the dbquit command.

Version History

Introduced before R2006a

See Also

| | |