The infinite loop that you've started isn't allowing any further events (i.e. the window close event) to be processed. You need to allow the interrupt mechanism to occur - although the 'interruptible'
property defaults to 'on'
, you have to satisfy another requirement:
If the Interruptible property of the object whose callback is executing
is on, the callback can be interrupted. However, it is interrupted
only when it, or a function it triggers, calls drawnow, figure,
getframe, pause, or waitfor. Before performing their defined tasks,
these functions process any events in the event queue, including any
waiting callbacks. If the executing callback, or a function it
triggers, calls none of these functions, it cannot be interrupted
regardless of the value of its object's Interruptible property.
Since you have a loop, you can insert a pause
or drawnow
command to allow MATLAB to process other events, such as mouse clicks on other buttons (pause(0)
may work - haven't tested - to allow checking for interrupt events without actually causing the loop to slow if there are no interrupts).
(Side note: ctrl-c breaks out of loops, so you could always do that but... not ideal.)