MATLAB debugging: smarter way to stop the code with an specific condition?

One of the ways is using Conditional Breakpoints. You can add them by right clicking on the number of the line and selecting the "Set conditional Breakpoints..." option.

Example:

enter image description here

As described in the comments of this answer, if you want to set it with the command line you can use

dbstop in filename at linenumber if condition 

As an example:

dbstop in banana at 6 if ii==454345433

note, that the at linenumber and if condition are optional.

More things

Another useful tool of the debugger is breaking the program if there has been an error, using dbstop if error, as show in this Q&A.

Thanks to @Dev-il for showing me this!

Leave a Comment