필터 지우기
필터 지우기

flush uicontrol callback queue

조회 수: 7 (최근 30일)
Wesley Ooms
Wesley Ooms 2014년 1월 9일
댓글: Wesley Ooms 2014년 1월 9일
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에서 Interactive Control and Callbacks에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by