I’m using GUIDE to create GUI in Matlab. When user hits “Start” button in GUI it starts optimisation task in background that runs in endless loop. Every iteration it outputs some information to GUI.
When I press that start button and then close GUI window Matlab freezes. When I run GUI but do not press “start” button and just close GUI it does not freeze.
How can I avoid freezing ?
As noted by tmpearce in his answer in order for function (callback) to be interrupted it have to contain call to drawnow, figure, getframe, pause, or waitfor. And property
interruptiblehas to be set toonon the button GUI component.So I put pause inside the infinite (endless) cycle. However it did not work well:
pause(0.0000000000000001)did slow down progress significantly (I did measure it so it isn’t subjective).pause(0)did not slow down the cycle and allowed for GUI to update but did not allow to execute any other callbacks after another button was pressed.I ended up using
drawnow;command inside the cycle. It did not significantly slow down the cycle (less then 5% slow down) and the GUI works as expected.