Every so often we’re lucky enough to have a customer come visit MathWorks and talk to us about his or her MATLAB experience. This week one such user gave us a great presentation of his image processing application and concluded with a wish list of features. On that list he expressed the desire to set a break point to debug a file on a particular index of a loop instead of every iteration. This function has been available for quite awhile in MATLAB, but I don’t fault the user for not knowing about it, it’s not particularly prominent.
You can set code to break on a particular variable value, loop index, error condition, or really any MATLAB expression with a conditional breakpoint. To set a conditional breakpoint in the editor:
Instead of breaking on a particular variable value, I could stop when an error occurs. For instance, if I knew that some time after this loop starts an error is thrown but I don’t know exactly when, I could use dbstop if error to break when the error happens and inspect my state and debug at that point, rather than at specific iteration of the loop. For more information on these dbstop conditions, see this earlier article.
By
Michael Katz
Mike is a developer on the MATLAB Mobile team. When not describing himself in the third person, biking, homebrewing, or rooting for the home team, he's busy trying to make the world a better place for programming.
Great tip. I didn’t realize Matlab did this. I always put in an if statement with the condition I needed.
@Brian,
Glad I could help!