My 'while' loop no longer recognizes stop.
显示 更早的评论
This used to work:
while ( strcmp(get(hObject,'String'),'Stop') )
stuff
end
This while loop for running an animation is in the callback for a GUI button that changes between 'Start' and 'Stop' when pressed.
It used to be that the button was enabled during the execution of the 'while' loop, such that pushing the button again would stop the animation.
In R2016b, that no longer seems to be the case.
==> Is there a way for GUI buttons to be enabled during a callback 'while' loop, or is there another kind of loop that can be aware of changes so that it can be interrupted?
5 个评论
Rik
2017-11-2
I am using a very similar trick to interrupt a long looped calculation and I have no problems on R2017b or R2012b. So are you sure nothing else changed? Have you tried what output that get is giving you when you don't use a loop?
David Christhilf
2017-11-2
Rik
2017-11-2
It is very unlikely this works in R2012b and R2017b, but not R2016b.
I did use a callback to set a value. You can even store a boolean in the struct you save in guidata (don't forget to reload your guidata every loop iteration if you go down that path).
David Christhilf
2017-11-2
Rik
2017-11-2
You are storing handles before reloading it, which will overwrite any changes made in a callback.
回答(1 个)
Walter Roberson
2017-11-2
0 个投票
You do not appear to have a drawnow() or pause() or uiwait() or waitfor() or figure() to allow the graphics queue to be flushed to permit the interrupt of clicking the button to be serviced.
类别
在 帮助中心 和 File Exchange 中查找有关 Animation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!