MATLAB: Close command and Invalid figure handle

closefiguregui

I have a GUI in which I have a button create a plot: p(1)=plot(…).
I have a reset button that, upon being pressed, executes close(p).
When I hit the reset button, I get the error:
??? Error using ==> close at 94
Invalid figure handle.
Error in ==> Pulse>reset_Callback at 870
close(p)
However, while the GUI and p(1) plot figure are open, if I type close(p) in the Matlab Command Window, it closes the figure without any errors. Any idea what's causing this?

Best Answer

Or:
close(ancestor(p, 'figure'))
Related Question