closing the figure window when pressing the mouse button on the X

9 views (last 30 days)
alex on 21 Oct 2012
I have a GUI that runs for a few minutes. in this GUI I have images that are shown continuesly using the lines-
axes('Position',[.3 .25 .3 .5]);
the problem is that even if I use my mouse to close the window by pressing the X in the left upper edge , there is a new window opened up showing those images until the end.
so how can I break the GUI from working (closing it) without getting a new window.
I guess its something like the "windowbuttonpressfcn" or "buttonpressfcn", but-
I dont think that pressing on the x is considered as a press becuase its outside the window.. I tried using the get(hobject,'currentpoint') but it didn't work and I think that's not the way..
I should mention that just preventing the new window to pop won't help me because I have also audio files that will keep on playing.
I need something that will r3ealy stop the entire procces , not only whats seen on the screen.

Accepted Answer

Jan on 21 Oct 2012
The CurrenPoint is not useful here.
Instead of creating new axes and images again and again, it would be more efficient to re-use the existing elements. And this would implicitly solve your problem also:
FigH = figure;
AxesH = axes('Position', [0.3, 0.25, 0.3, 0.5], 'Parent', FigH);
ImageH = [];
for ii = 1:1000
if ~ishandle(AxesH)
disp('Stopped by user');
if isempty(ImageH)
ImageH = image(imcell{1,2}, 'Parent', AxesH);
set(ImageH, 'CData', imcell{1,2});
... Your code to create the new image here

More Answers (0)


Community Treasure Hunt

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

Start Hunting!