GUI still executing code after it is closed
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
I have a Matlab GUI and when a push button is pressed it performs a very long computation(hours long). If during this computation I decide I want to stop or doing something else I will press the close button(default top right corner). This will close the GUI(via an interrupt). However after the figure has closed the code continues to run, eating up system resources, and displaying graphs. When running matlab this hasn't been problem as I just use ctrl C to stop this as well. Now that I have compiled this and am about to redistribute this I need a way to completely stop the code without having the users do control alt delete.
I have tried various things in the CloseRequestFcn such as: 1) delete(handles.gui) 2) set(groot,'ShowHiddenHandles','on') c = get(groot,'Children'); delete(c) 3) delete(hObject); 4) close all force
None of which have worked.
0 Kommentare
Antworten (1)
Walter Roberson
am 27 Aug. 2015
Graphics interrupts are not executed until the code calls figure() or pause() or drawnow() or uiwait() or waitfor()
You could have your code structured something like,
myfig = handle of your figure
user_quit = false;
for K = 1 : 324
for J = 1 : 3439324
drawnow();
if ~isgraphics(myfig);
%user closed the figure. React appropriately
user_quit = true;
break;
end
%now do a bite-sized amount of code, a couple of seconds or so
....
end
if user_quit; break; end
end
I used this structure as an example, to illustrate the point that "break" only breaks out of the innermost loop so you may need a check to break out of the outer loop
Siehe auch
Kategorien
Mehr zu Migrate GUIDE Apps finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!