Borrar filtros
Borrar filtros

How to stop the program while closing the figure that shows an animated plot

8 visualizaciones (últimos 30 días)
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.

Respuesta aceptada

Stephen23
Stephen23 el 11 de Mzo. de 2015
Editada: Stephen23 el 11 de Mzo. de 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 comentarios
Mehdi
Mehdi el 11 de Mzo. de 2015
Thank you Stephen. The ishandle method works fine!
Stephen23
Stephen23 el 11 de Mzo. de 2015
For robustness reasons you should use ishghandle rather than ishandle.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Graphics Object Programming en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by