MATLAB: Please dbstop here
I am doing a lot with MATLAB at work. I wanted the equivalent of a command that doesn't exist:
dbstop here or
dbstop now. Came up with two possible solutions with the help of the MathWorks tech support.
1: (from MATLAB documentation)
dbstop if warning 'MFILE:stop'; % Then later: if ~isequal(input, expected_input), warning('MFILE:stop','Boom!'), end; % At the end (or else things seem to slow down) dbclear if warning 'MFILE:stop';
When it drops into the debugger you can then issue the above
dbclear command by hand to get it to stop dropping there.
2: (my way)
This way uses the command
keyboard that I didn't know about until tech support told me about it - it is not listed in
help dbstop but it is a "see-also" in
doc dbstop which is annoying…
breakable=1; % Then later: if breakable && ~isequal(input, expected_input), keyboard, end;
When it drops into the debugger (you can still use F5, etc) you can then type
breakable=0; to stop it from dropping at that point. It doesn't clutter up the
dbstop stack so shouldn't slow down unrelated M-files.