cancel running program with crtl+c - is it possible to recover the processed data?

13 views (last 30 days)
Hello everybody,
I have a question concerning the termination of running programs with the combination ctrl+c (or ctrl+pause). Appearently, all data processed by the program is deleted once the combination is pressed on the keyboard. Are there any alternatives to this way of terminating programs, with which the processed data can be recovered (maybe even displayed in the workspace)?
See you and thanks in advance!

Answers (4)

Sean de Wolski
Sean de Wolski on 22 Aug 2011
All data inside the function is cleared since it has its own workspace and that workspace is terminated.
The easiest way would be to not use a function but a script instead, then when it's terminated the variables are all left in your base workspace. Or use a script with a bunch of functions returning variables so that you only lose the current variables, not all of the ones processed previously.
As far as termination, why are you terminating it manually? Why not let it run to completion? Please clarify your goals a little bit.

Fangjun Jiang
Fangjun Jiang on 22 Aug 2011
The data is not necessarily deleted. When you press ctrl+c, the program will stop. It usually tells you where it stopped. The data in the base workspace is still there. You could save the data or use it whatever the way you like. But of course, there is no guarantee you can stop the execution of the code at a particular place.
If the execution is stopped when running a function, the data in the function workspace is lost.

Jan
Jan on 22 Aug 2011
You could create a tiny GUI-figure, which contains a single Toggle-button. The you program checks the status of the button in each loop or section, after it called DRAWNOW to give the mouse events a chance to be processed. If the button is pressed, the KEYBOARD command let the program stop, but it does not delete the current variables.
function yourProgram
figure;
ButtonH = uicontrol('Style', 'ToggleButton', 'String', 'Stop', ...
'Value', 0);
for i = 1:1e6
drawnow;
if get(ButtonH, 'Value') == 1
keyboard;
end
end

JuAdam
JuAdam on 22 Aug 2011
Hey everybody, thank you very much for your answers!
The problem with my program is, that it is implemented as a function. I think I'll just run the program as a script for now - however, I might implement the GUI-proposal later!
Thank you!

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!