Development Environment    

Debugging M-Files

This section introduces general techniques for finding errors, and then illustrates MATLAB debugger features found in the Editor/Debugger and equivalent debugging functions using a simple example. It includes these topics:

In addition to the Debugger and debugging functions, the Profiler included with MATLAB can be a useful tool to help you improve performance and detect problems in your M-files. For details, see Measuring Performance in the Programming and Data Types section of the MATLAB documentation.

Types of Errors

Debugging is the process by which you isolate and fix problems with your code. Debugging helps to correct two kinds of errors:

Finding Errors

Usually, it is easy to find syntax errors based on MATLAB error messages. Run-time errors are more difficult to track down because the function's local workspace is lost when the error forces a return to the MATLAB base workspace. Use the following techniques to isolate the causes of run-time errors:

The remainder of this section on debugging M-files describes the use of the Editor/Debugger and debugging functions using an example.


  Closing M-Files Debugging Example--The Collatz Problem