Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to stop a running script in Matlab [duplicate]

Tags:

windows

matlab

I write a long running script in Matlab, e.g.

tic;
d = rand(5000);
[a,b,c] = svd(d);
toc;

It seems running forever. Becasue I press F5 in the editor window. So I cannot press C-Break to stop in the Matlab console.

I just want to know how to stop the script. I am current use Task Manager to kill Matlab, which is really silly.

Thanks.

like image 618
Yin Zhu Avatar asked Jan 25 '11 08:01

Yin Zhu


People also ask

How do you stop a script execution in MATLAB?

To stop execution of a MATLAB® command, press Ctrl+C or Ctrl+Break.

How do I stop a live script?

Accepted Answer If you run it in the command window, you can then interrupt the execution of the live script by using Ctrl + C, as usual.

How do you stop an infinite loop in MATLAB?

when an loop is running ctrl + c (just ctrl and c ) will exit any loop..

Can I pause MATLAB execution while it is already running?

Typing pause(inf) puts you into an infinite loop. To return to the MATLAB prompt, type Ctrl+C. Example: pause(3) pauses for 3 seconds. Example: pause(5/1000) pauses for 5 milliseconds.


2 Answers

Matlab help says this- For M-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, you can help MATLAB break execution by including a drawnow, pause, or getframe function in your M-file, for example, within a large loop. Note that Ctrl+C might be less responsive if you started MATLAB with the -nodesktop option.

So I don't think any option exist. This happens with many matlab functions that are complex. Either we have to wait or don't use them!.

like image 78
S Krishna Kumar Avatar answered Sep 22 '22 12:09

S Krishna Kumar


If ctrl+c doesn't respond right away because your script is too long/complex, hold it.

The break command doesn't run when matlab is executing some of its deeper scripts, and either it won't log a ctrl sequence in the buffer, or it clears the buffer just before or just after it completes those pieces of code. In either case, when matlab returns to execute more of your script, it will recognize that you are holding ctrl+c and terminate.

For longer running programs, I usually try to find a good place to provide a status update and I always accompany that with some measure of time using tic and toc. Depending on what I am doing, I might use run time, segment time, some kind of average, etc...

For really long running programs, I found this to be exceptionally useful http://www.mathworks.com/matlabcentral/fileexchange/16649-send-text-message-to-cell-phone/content/send_text_message.m

but it looks like they have some newer functions for this too.

like image 25
Mach Avatar answered Sep 22 '22 12:09

Mach