Question

I'm running a long simulation in MATLAB that I've realized I need to stop and rerun. However, MATLAB is really into this calculation, and it's stopped responding. How can I interrupt this run without killing MATLAB?

(I realize this is a problem with many Windows programs, but it's really acute with MATLAB.)

Was it helpful?

Solution

Go to the command window, and hit Ctrl-C a lot. From my experience, on a single-core machine you do not have a chance, unless you do lots of output. On a multi-core or multi-processor machine, you'll probably stop it eventually, but it takes time.

See also http://www.mathworks.com/support/solutions/en/data/1-188VX/index.html

Added: it is a good practice to (1) save a snapshot of your workspace before running anything really long and (2) within a very long calculation, write some of the variables to a file from time to time, so that you can resume the calculation if it was interrupted (by power failure, e.g.).

OTHER TIPS

How well MATLAB responds to CTRL-C rather depends on what it's doing. If it's in the middle of a BLAS or LAPACK call for example, it will not respond until that call returns. If you're in a block of code where lots of lines of MATLAB are being executed, you can expect CTRL-C to be more responsive.

I have got a very simple trick to pause (or stop) a non-responsive execution. If my simulation is running a long loop I always do the following:

for ii = 1:N
   do_stuff();
   clear empty_script;
   empty_script;
end

And then create a file empty_script.m containing the following:

%keyboard

Whenever I want to pause execution I open an external text editor and uncomment the line saying keyboard in empty_script.m. That leaves me in debugging mode where I can watch variables, modify stuff or even stop the program.

Another strategy for dealing with this problem is to introduce a very short pause somewhere in the calculation (especially in a FOR or WHILE loop), as in:

for ii = 1:N
do_stuff();
pause(0.1);
end

This increases the chances that your maniacal Ctrl-C'ing will actually stop it.

you can find the MATLAB process in the windows task manager and set the priority as high or low and let other program to have lower or higher priority. In my experience, it is an efficient way.

if you wont to stop and rerun then killing is not bad choise Go to windows task manager-> Processes then fined MATLAB.exe and push the End Process button

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top