Version (981 Bytes) by Dan K.
dbstopif is a much faster replacement for the built in conditional breakpoint
Updated 16 May 2017

View License

When working with long loops of processing one may need to set a breakpoint to stop on a particular condition. While Matlab's built in conditional breakpoints achieve this, they exact a heavy performance penalty (even when disabled!), and are not generally maintained between sessions. dbstopif is inserted as a single line of code which which, if the condition is true, sets a regular breakpoint on the following line, resulting in an immediate dbstop.
A comparison of the time to execute a loop with many iterations:

Matlab conditional breakpoint enabled: Elapsed time is 34.412000 seconds.
dbstopif: Elapsed time is 0.004994 seconds.

Matlab conditional breakpoint disabled: Elapsed time is 51.132263 seconds.
dbstopif: Elapsed time is 0.004941 seconds.

Matlab conditional breakpoint removed: Elapsed time is 0.004422 seconds.
dbstopif: Elapsed time is 0.004628 seconds.

Cite As

Dan K. (2024). dbstopif(condition) (https://www.mathworks.com/matlabcentral/fileexchange/62969-dbstopif-condition), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2017a
Compatible with any release
Platform Compatibility
Windows macOS Linux
Find more on Programming in Help Center and MATLAB Answers

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes