How to stop the program while closing the figure that shows an animated plot
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Mehdi
am 11 Mär. 2015
Kommentiert: Stephen23
am 11 Mär. 2015
Hello everyone,
I've designed a figure which shows a 2-D animation of a plot using drawnow . When I click on close button, it closes the figure but the program still runs for a short while and then gives an error. How can I have the program "understand" that it should stop running as soon as I click on the close button? Thank you in advance.
0 Kommentare
Akzeptierte Antwort
Stephen23
am 11 Mär. 2015
Bearbeitet: Stephen23
am 11 Mär. 2015
Presumably your program uses a loop of some kind. One easy way is to check at the start of the loop for the existence of the figure itself, and break out of the loop if the figure does not exist any more. You can use ishghandle to check specifically for graphics handles:
figH = figure;
for k = 1:frames
if ~ishghandle(figH)
break
end
...
end
Note that this may still result in some errors if the figure is closed at some time during the loop but the code still tries to access the graphics.
Another way is to rely on callbacks. This means integrating the code quite closely with the figure/axes, so that the loop itself is part of a callback. This will complete the current callback before closing the window, so errors do not occur. For an example of this, see my FEX submssion cubehelix_view, and try the demo button:
2 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Graphics Performance 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!