File Exchange Pick of the Week

March 15th, 2006

Stop it!

Sometimes you just know you are going to want to break out of a loop in MATLAB, but ctrl-C is not what you are looking for because you are going to want to debug. A conditional breakpoint is not going to work either (right click on a breakpoint in the editor to make it conditional). Greg Aloe’s post: dbloop will do the job quite nicely. It will have MATLAB listen for a certain keypress and then enter debug mode in the middle of the loop. Brilliant!

6 Responses to “Stop it!”

  1. Antenna Geek replied on :

    Regarding Ctrl-C loop breaking:

    It frequently happens on my machine that MATLAB won’t break out of a loop on Ctrl-C. It is running at 100% CPU and is not “listening” to Ctrl-C until the program is completed.

    I usually insert

    pause(0.01);

    into the loop and that solves the problem.

    Regards,

    Eric

  2. Kevin Murphy replied on :

    Instead of pause(0.01), I find adding a ‘drawnow’ command makes matlab ‘listen’ to ctrl-C

    Kevin

  3. Bob replied on :

    How much does dbloop slow down a program?

  4. Malambo replied on :

    I have designed a GUI for image classification. I have used a for loop for selecting samples using roipoly. The problem i have is that i can not zoom while selecting my samples. Is there a way I could pause the for loop to zoom to an area of interest and resume afterwards?

  5. Doug replied on :

    Malambo,

    I suspect that you are going to need to change your architecture slightly to accomplish this. Once you are running ROIPOLY, you will not be able to zoom. I would make a button that says “Capture” that then gets you in capture mode. You can zoom as normal between captures.

    Doug

  6. Roy replied on :

    If you run Matlab from the linux terminal, you can do ctrl-c at the commandline/terminal to stop and close Matlab

Leave a Reply

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).


MathWorks

Brett & Jiro share their favorite user-contributed submissions from the File Exchange.

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