Debugging MATLAB

So today I discovered two tricks for debugging in MATLAB which I’m sure will help me immensely. First, I discovered that my breakpoints were disappearing every time I start a script because the command clear all actually clears all breakpoints. I tend to start scripts with the line

in order to get a fresh workspace, but it also happens to clear all existing breakpoints. The second trick is perhaps the greatest MATLAB-related thing I’ve ever stumbled upon. By typing dbstop if error into the command window, a global breakpoint is set which will pause in debug mode anytime an error occurs. Finally! No more stepping through 1000’s of for loop itterations to find the one data instance which breaks my code. Using dbstop if error will just run until an error occurs and then let me look at the local workspace to see what went wrong. It’s really useful for debugging functions, which have their own local workspaces.

EDIT: The debugging behavior can be turned off with the command dbclear all

Updated: February 10, 2015 — 9:08 am

Leave a Reply

Your email address will not be published. Required fields are marked *

DrewBuck.com © 2015 Frontier Theme