File Exchange

image thumbnail

Pause a long MATLAB run with a simple click.

version 1.2.0.0 (730 Bytes) by Roni Peer
A simple way to pause a long simulation, to check progress, without expensive breakpoints or checks

8 Downloads

Updated 19 Apr 2016

View Version History

View License

Sometimes you create MATLAB functions that take ages to run (more than 10 minutes). You want to be able to pause every now and then, by clicking a "CTRL+P" or something like that, make sure all the values are ok, and then continue running from the same spot. If you tried "CTRL+C", you know it's not working well. So, untill such an option will exist, I wrote a simple example to show how you can use a PushButton and a guarded breakpoint to do so.
Run the file, by executing "myFunc(1)".
You will see a button pop up. Every time you press it, it will halt the function's execution and allow you to view the progress of the code.
Pressing F5 will continue the run.
You can use this as a template for your specific needs, simply modify and use.
PLEASE NOTE: In MATLAB version R2016a this feature is already a part of the editor, so you don't really need this submission anymore. Hooray for MathWorks development team for adding this feature!

Cite As

Roni Peer (2020). Pause a long MATLAB run with a simple click. (https://www.mathworks.com/matlabcentral/fileexchange/35114-pause-a-long-matlab-run-with-a-simple-click), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (10)

Achraf Kabbabi

Xiaoyu Qian

I'm now running a script. It takes a long time. I want to pause it whenever I want and see the partial result. If the partial result is not good enough, I want it to continue running. Can I do it with this file? To be honest, I'm a little confused with this file. Could anyone please explain it in detail? I appreciate it a lot!

Roni Peer

Thanks for the comment, I've updated the submission to reflect this.
Btw, interesting point:
Running on R2015b, the code "myFcn(1)" takes about 1000 seconds to run.
The same code on R2016a takes 2 seconds!
Seems like there was something strange with 15b and was fixed in 16a.

MertLab

Works great. Like Stefano suggested, using close(h) while running functions is better than clear h to close the pause button.

Gero Nootz

Works well. It would be nice if the script would resume after pressing the button a second time (e.g. execute “dbcont”). Thanks for sharing it.

Aamir

Stefano

Really useful! Thanks!
The last lines of myFcn(u) should actually be:

close(h)
clear h

So that the "pause" plot window is closed and h is released.

Seban

Works like a charm :)

Roni Peer

Good suggestion, Jan. I've modified the files so they reflect this.
Thanks!

Jan

What about calling KEYBOARD in the callback of the button? Then there is no need for a GLOBAL variable or setting a breakpoint. See "help keyboard".

MATLAB Release Compatibility
Created with R2011b
Compatible with any release
Platform Compatibility
Windows macOS Linux
Acknowledgements

Inspired: Soft interrupting of long computer runs

Community Treasure Hunt

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

Start Hunting!