MATLAB provides a debugging facility that allows you to stop at specific points in your .m files, examine the workspace and step through execution of your code. For example, while developing a function ops.m, an error occurs. Matlab will give an error message similar to:
The first 2 lines explain the error, and the next two give the location of the error. To use the debugging facility to determine what is happening, you start with the "dbstop" command. This command provides a number of options for stopping execution of a Matlab function. A particularly useful option is
This causes a stop in any M-file function causing a run-time error. Then just run the Matlab command. In this case
Execution will stop at the point where the error occurs, and you will get the Matlab prompt back so that you can examine variables or step through execution from that point. In the example:
The command "dbstep" allows you to step through execution one line at a time. You can continue execution with the "dbcont" command. To exit debug mode, type "dbquit".
For more information, see the Matlab help for the following topics:
debug, dbstop, dbclear, dbcont, dbdown, dbstack, dbstatus, dbstep, dbtype, dbup, dbquit