MATLAB: How to close two figures by pressing the mouse button on the X just once

closefiguresoncepress button

I have two figures open. Their axes are linked using linkaxes. Is there a way that I can close both figures by pressing the mouse button on the X just once (on either figures)?
Many thanks,
Anantawit

Best Answer

You would probably have to use event listeners. The following is an example of how you could do this for 2 open figures.
h(1)=figure(1); h(2)=figure(2);
addlistener(h(1),'ObjectBeingDestroyed',@(s,e) close(h(2)));
addlistener(h(2),'ObjectBeingDestroyed',@(s,e) close(h(1)));