MATLAB Answers

Can I stop MATLAB when it's being busy?

조회 수: 2,886(최근 30일)
matar maoz
matar maoz 30 Jun 2011
댓글: Walter Roberson 17 Mar 2020
If MATLAB runs a code, and takes not responding (displaying 'Busy' at the lower bar, next to start button), it removes the - >> sign from the command window, and I cant do anything but close it from the windows's task manager.
Is there a more elegant approach to that problem?
Matar Maoz

  댓글 수: 0

로그인 to comment.

채택된 답변

Jan
Jan 30 Jun 2011
Sometimes even Ctrl-C does not work, when Matlab has no chance to evaluate the events. Therefore a DRAWNOW can be helpful in longer loops. Even in Mex files this can be done using mexCallMATLAB.

  댓글 수: 2

matar maoz
matar maoz 30 Jun 2011
It's funny to see the same faces each time I ask something.
Thank you very much. You have ended a few days of frustration.
the DRAWNOW didnt do anything, although the ctrl+c did the job.
thanks again
Matar
KAE
KAE 22 Jan 2020
If I am having trouble ending a program with CTRL-C, I should include the drawnow command inside my loop, even if my program makes no plots, right? In other words, no drawing is necessary.

로그인 to comment.

추가 답변(5개)

Andrei Bobrov
Andrei Bobrov 30 Jun 2011
Ctrl+Break

  댓글 수: 3

matar maoz
matar maoz 30 Jun 2011
can you please be more specific?
Matt Fig
Matt Fig 30 Jun 2011
I did not know about ctrl+Break. Thanks andrei!
Yujia Zhai
Yujia Zhai 1 Jun 2019
Come on! Why dont you just talk to Matlab and indicate it to stop?

로그인 to comment.


Fangjun Jiang
Fangjun Jiang 30 Jun 2011
I usually press ctrl+c or ctrl+d.
I don't know how I get the idea of pressing ctrl+d but I remembered it worked sometimes. Here is a reference to the MATLAB documentation.
Stopping Execution
To stop execution of whatever is currently running, press Ctrl+C or Ctrl+Break. On Apple Macintosh platforms, you can also use Command+. (the Command key and the period key) to stop the program. For certain operations, stopping the program might generate errors in the Command Window.
For files that run a long time, or that call built-ins or MEX-files that run a long time, Ctrl+C does not always effectively stop execution. Typically, this happens on Microsoft Windows platforms rather than UNIX[1] platforms. If you experience this problem, help MATLAB break execution by including a drawnow, pause, or getframe function in your file, for example, within a large loop. Note that Ctrl+C might be less responsive if you start MATLAB with the -nodesktop option.

  댓글 수: 2

matar maoz
matar maoz 30 Jun 2011
in matlab r2010b there is no such hot key combo as ctrl+d
only the ctrl+shift+d which docks the current pane.
niraj
niraj 13 Mar 2019
Thanks Fangjun Jiang, control+break definitly works, even in worst situation. My MATLAB was struck in a never ending plot loop, still it worked by pressing control+break.

로그인 to comment.


Adrian Jacov
Adrian Jacov 23 Aug 2016
Excelente gracias,

  댓글 수: 0

로그인 to comment.


Muhammad Usama Sharaf SAAFI
You should press ctrl+c in such scenarios.
MATLAB will stop all excecution.

  댓글 수: 1

Walter Roberson
Walter Roberson 17 Mar 2020
control+c will not alway stop immediately. In fact, it can take a number of hours before it stops in some cases.

로그인 to comment.


Kaveh Vejdani
Kaveh Vejdani 17 Mar 2020
This is one of the major flaws of MATLAB. Although Ctrl+C "sometimes" works, the very fact that it doesn't "always" work makes it a major blunder on behalf of mathworks. The absurd yet only solution in these situations is to close down MATLAB and launch it again.

  댓글 수: 2

Walter Roberson
Walter Roberson 17 Mar 2020
MATLAB calls into third-party libraries such as LAPACK and MKL for high performance computation.
Mathworks cannot know when it is safe to interrupt those libraries -- do not know, for example, whether they are in the middle of a memory operation that could lead to references to memory being lost, or lead to corrupt pointers if the operation is interrupted. Therefore Mathworks cannot safely force a termination when it has made a call into one of those libraries... and those libraries do not generally provide a hook to terminate them early.
Therefore in order to resolve this "major blunder on behalf of mathworks", it would be necessary for Mathworks to get the source code for each of those libraries, and make a customized version of them that had safe interruptions built in, and it would have to add those changes in to every new release from the third-party. This is a fair bit of work, and it is likely to introduce bugs and subtle incompatibilities.
Source code for LAPACK is made available, and there is even a tool available to optimize the heck out of LAPACK for any given nardware / software configuration (the tool usually takes about 30 hours to run!) so for LAPACK it is theoretically possible to do.
However, MKL is an Intel product that it supplies only in binary form. I think that I heard about 5 years ago that a source code license cost $US 1 million. It is highly optimized for each different intel CPU type, with specific machine language calls, so it would be a lot of work for Mathworks to maintain its own custom version just for the purpose of permitting clean interrupts.
Fine tuned code at the machine level, tuned by the manufacturers of the CPU, often has very very subtle (and possibly undocumented) interactions, such that adding in a single instruction that "logically" should work, can result in much much lower performance.
The one product that Mathworks has reasonable control over but does not do a good job on interrupts, is their Symbolic Toolbox. The MuPAD engine operates in a different process, and MATLAB sends the process commands and receives results, with there seeming to be no designed way at present for MATLAB to send an interrupt request. That is, however, under Mathworks' control, and at least on Mac and Linux, even without having to write new TCP protocol handling, MATLAB could use signal() to request an interrupt, and since it has full control over the code, could reasonably put in protected areas (to avoid corruption) and interrupt handlers. I think they could do better on that; it is their library. However, interrupts in third-party libraries are not reasonably under Mathworks control.
Walter Roberson
Walter Roberson 17 Mar 2020
A major cause, especially on Windows, that control-C can have no effect, is in the case where more RAM has been requested than is physically present, and the operating system is busy swapping to and from disk. I am not aware of any comoperating system that does a good job of interrupt handling in that situation; it seems to me that Windows is poor on this regard. This is an operating system matter, though, not a MATLAB matter.

로그인 to comment.

이 질문에 답변하려면 로그인을(를) 수행하십시오.


Translated by