flush uicontrol callback queue
4 次查看(过去 30 天)
显示 更早的评论
Hi, I want to show a continuously repeating animation that can be updated on the fly with pushbuttons. The problem is that a new function call cannot kill the previously running function. The function that was busy cannot kill itself since it was halted by the new call. another approach is to use one infinite loop and listen in that loop to changes made to the figure, but changes will never be made since the loop is busy. I cannot solve it with Busyaction/Interruptible. I tried to explain my example with the following piece of code. the buttons work 22 times and then the queue of interruptions is full. The buttons don't work anymore. In the real code the buttons work only 8 times. Is there a way to solve this? can i use some kind of threading to keep both processes running so that the old proces has time to kill itself?
function amimasteroramislave(varargin)
if ~nargin
clear all;close all;clc
it=1;
uicontrol('style','pushbutton','String','start slave 1 kill slave 2','FontSize',16,'HorizontalAlignment','center', ...
'Position',[10,10+40*(it-1),260,30],'Tag','masterbutton1','Callback',{@amimasteroramislave,1})%,'Interruptible','Off');
uicontrol('style','pushbutton','String','kill slave 1,start slave 2','FontSize',16,'HorizontalAlignment','center', ...
'Position',[10,10+40*(2-1),260,30],'Tag','masterbutton2','Callback',{@amimasteroramislave,2})%,'Interruptible','Off');
while 1
'Hello from master'
pause(1)
get(findall(0,'Tag','masterbutton1'),'Value')
get(findall(0,'Tag','masterbutton1'),'Selected')
end
else
while 1
['Hello from slave ' num2str(varargin{3})]
pause(1)
get(findall(0,'Tag','masterbutton1'),'Value')
get(findall(0,'Tag','masterbutton1'),'Selected')
end
end
0 个评论
采纳的回答
Sean de Wolski
2014-1-9
Use a timer or multiple timers. They will handle this much better than while-loops. Don't forget to be liberal with the drawnow's either so that the queue can be flushed.
3 个评论
Sean de Wolski
2014-1-9
I don't have time right now. But this has certainly been demonstrated here before.
Is probably a good start
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Migrate GUIDE Apps 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!