How can I interrupt MATLAB when it gets really rea

2019-03-22 20:33发布

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

6条回答
干净又极端
2楼-- · 2019-03-22 20:57

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.

查看更多
手持菜刀,她持情操
3楼-- · 2019-03-22 20:58

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

查看更多
欢心
4楼-- · 2019-03-22 21:03

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

查看更多
做个烂人
5楼-- · 2019-03-22 21:07

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.

查看更多
狗以群分
6楼-- · 2019-03-22 21:14

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.

查看更多
做自己的国王
7楼-- · 2019-03-22 21:14

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.

查看更多
登录 后发表回答