This function is like MATLAB's useful built-in 'keyboard' function, which lets you stop in the middle of a function, examine or change variables, and do debugging.
The new functionality in kbd is that you can disable or enable it as you like. For instance, if you have a function that calls kbd, you can type 'kbd off' to run the function straight through, just as if you had removed the calls to kbd. Later, if you want to re-enable the kbd command, just type 'kbd on'.
To use this command, you will need to compile the MEX C-file (for those new to MEX files: navigate in MATLAB to the folder containing kbd.c, type 'mex kbd.c', and you will get a file starting with kbd.mex... that you can put anywhere on your MATLAB search path.)
-- enters keyboard mode, if enabled
-- disables the kbd command
-- enables the kbd command
s = kbd('state')
-- returns 1 if kbd is currently enabled and 0 otherwise.
For more information on MATLAB's keyboard command, you can check out the MATLAB documentation.
Update 6/10/14: "dbquit" now works inside kbd as it should.
- There is no reason you have to do this with MEX, but the advantage is that MATLAB can't step through MEX files, so when executing kbd, it stops in the function calling kbd instead of inside kbd itself.
- For some reason, if you use dbstep to step through code after entering kbd, you have to type dbstep twice in order to move onto the next command. I'm not sure why.
Peter Caday (2022). kbd (https://www.mathworks.com/matlabcentral/fileexchange/46682-kbd), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform CompatibilityWindows macOS Linux
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!