can i pause matlab excution while it is already running

154 visualizaciones (últimos 30 días)
gasser el 26 de Mzo. de 2013
Comentada: Walter Roberson el 25 de Mzo. de 2020
hi every on ,
can i pause matlab excution while it is already running
(i.e) if i have a script and is already running can i pause it for any time then resuming it again .
thanks a lot .
  2 comentarios
Walter Roberson
Walter Roberson el 31 de Mayo de 2016
That will not work unless there is a figure() or drawnow() or pause() or waitfor() or uiwait() somewhere in the code. Pushbuttons are not serviced until the graphics queue is processed, which requires one of the above to happen.

Iniciar sesión para comentar.

Respuestas (6)

Nick Hilton
Nick Hilton el 12 de Oct. de 2015
If you're on a UNIX platform, then there is an easy way to do this:
Simply run your script on the command line in a BASH shell like so:
matlab -nodesktop -nosplash -r "run_some_script(arg1, arg2, ...)"
Now that it is running, you can pause execution by pressing CTRL+Z, which pauses execution and returns you to the BASH prompt again. To continue execution, execute the 'fg' command to put the suspended job back into the foreground.
Another advantage to this approach, most graphical terminals provide an output buffer, and one can scroll and examine the output buffer without pausing the execution, and without new output causing the buffer to scroll the screen. So I can look at the buffer to tell where the execution is in a loop, for example, without pausing anything.
I hope this helps someone that finds this topic.
  3 comentarios
Walter Roberson
Walter Roberson el 15 de Sept. de 2018
To consult the output buffer, use the Page Up / Page Down keys, or use whatever scrollbar your terminal application provides. Here, "output buffer" refers a configurable number of lines of stdout .
For example on OS-X, inside the utility, Preferences -> Profiles -> Window permits me to configure whether I want scrollback to be limited to available memory, or to a specific number of output lines.

Iniciar sesión para comentar.

Image Analyst
Image Analyst el 31 de Mayo de 2016
With R2016a, there is now a Pause button on the tool ribbon that appears when your code runs:

Mahdi el 27 de Mzo. de 2013
You can pause the script/function that you're running for a specified amount of time without quitting the script.
You can use the pause(n) function to stop the script for n seconds.
If you're using a GUI, I would suggest looking at uiwait.

Jan el 26 de Mzo. de 2013
  2 comentarios
Walter Roberson
Walter Roberson el 26 de Mzo. de 2013
You might also be able to suspend MATLAB from the operating system.

Iniciar sesión para comentar.

Omer Moussaffi
Omer Moussaffi el 14 de Dic. de 2014
Not without preparation. You could add the command 'keyboard' into the script at a specified place, and then it would give you back control. You then do your changes, and either call 'return' to resume or dbquit to stop the script.

jingxuan yang
jingxuan yang el 24 de Mzo. de 2020
to pause
and use
to continue
  1 comentario
Walter Roberson
Walter Roberson el 25 de Mzo. de 2020
Yes, if you have the cooperation of the code being run, if it knows that you should pause there, or if it regularly calls one of the functions such as drawnow() that processes the event queue to permit a callback to be triggered to run the uiwait()

Iniciar sesión para comentar.


Más información sobre Introduction to Installation and Licensing en Help Center y File Exchange.


Community Treasure Hunt

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

Start Hunting!

Translated by