RevRagnarok's blog - Bloghttp://www.revragnarok.com/blog/blog
RevRagnarok's Blogen-USTrac 1.2.2RevRagnarok's bloghttp://www.revragnarok.com/img/license.jpghttp://www.revragnarok.com/blog/blog
MATLAB: Please dbstop hereRevRagnarokFri, 12 Dec 2008 20:20:23 GMThttp://www.revragnarok.com/blog/blog/MATLAB/StopHere
http://www.revragnarok.com/blog/blog/MATLAB/StopHere<p>
I am doing a lot with MATLAB at work. I wanted the equivalent of a command that doesn't exist: <code>dbstop here</code> or <code>dbstop now</code>. Came up with two possible solutions with the help of the MathWorks tech support.
</p>
<p>
1: (from MATLAB documentation)
</p>
<div class="wiki-code"><div class="code"><pre>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';
</pre></div></div><p>
When it drops into the debugger you can then issue the above <code>dbclear</code> command by hand to get it to stop dropping there.
</p>
<p>
2: (my way)
</p>
<p>
This way uses the command <code>keyboard</code> that I didn't know about until tech support told me about it - it is <em>not</em> listed in <code>help dbstop</code> but it <em>is</em> a "see-also" in <code>doc dbstop</code> which is annoying...
</p>
<div class="wiki-code"><div class="code"><pre>breakable=1;
% Then later:
if breakable &amp;&amp; ~isequal(input, expected_input), keyboard, end;
</pre></div></div><p>
When it drops into the debugger (you can still use F5, etc) you can then type <code>breakable=0;</code> to stop it from dropping at that point. It doesn't clutter up the <code>dbstop</code> stack so shouldn't slow down unrelated M-files.
</p>
matlab