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

采纳的回答

Sean de Wolski
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
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
Wesley Ooms
Wesley Ooms 2014-1-9
Thanks for answering. I do not understand the timer very well (never worked with it), but I found a solution does the job using the matlab 'vibes' example. Userdata wil be the pointer to the data to animate. This is the code that gets the job done:
function amimasteroramislave(varargin)
clear all;close all;clc
fig = figure
it=1;
uicontrol('style','pushbutton','String','start slave 1 kill slave 2','FontSize',16,'HorizontalAlignment','center', ...
'Position',[10,10+40*(it-1),360,30],'Tag','masterbutton1','callback','set(gcbf,''userdata'',1)')%,'Interruptible','Off');
uicontrol('style','pushbutton','String','kill slave 1,start slave 2','FontSize',16,'HorizontalAlignment','center', ...
'Position',[10,10+40*(2-1),360,30],'Tag','masterbutton2','callback','set(gcbf,''userdata'',2)')%,'Interruptible','Off');
while ishandle(fig)
['Hello from slave ' num2str(get(fig,'userdata'))]
pause(.1)
end

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by