Doug's MATLAB Video Tutorials

Quick Tip: Speeding up debugging iterations

This week’s video is a quick tip to help speed up iterations when debugging MATLAB code. If your code requires user interactivity, such as selecting a file or folder from a dialog box, consider hardcoding a representative input value into your file while debugging. This eliminates for you to perform the interactive steps every time you run the code.

The video shows a couple of different approaches for switching between your debugging code and the code for the final version.

4 Responses to “Quick Tip: Speeding up debugging iterations”

1. Sean de Wolski replied on :

If you are using breakpoints in the file, you can use DBSTATUS to identify whether you’re debugging or not:

function broken

if isempty(dbstatus(mfilename))
file = uigetfile();
else
file = ‘foo.txt’;
end

a = b

end

Try it both with and without a breakpoint on line a = b

2. James K replied on :

Hey Doug,
Good call on the direct input when debugging. As a GUI developer I used to debug things this way and it slows you down so much.

I like the flagdebug idea, but what about using something like ? That way you won’t accidentally leave a flag on or off.

Thanks,
James

3. James K replied on :

*using “isdeployed”. Sorry, code fragment got deleted.

4. Doug replied on :

James,

That would be good improvement, but this mechanism I have exists now! :)

Doug

 Name (required) E-mail (required, will not be published) Website (optional) Spam protection (required): What is 9 + 10 ?

Wrap code fragments inside <pre> tags, like this:

<pre class="code">
a = magic(3);
sum(a)
</pre>


If you have a "<" character in your code, either follow it with a space or replace it with "&lt;" (including the semicolon).

Doug Hull is a proud MathWorker who is on a mission to help you with MATLAB.

These postings are the author's and don't necessarily represent the opinions of MathWorks.