flush uicontrol callback queue
4 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
Sean de Wolski
on 9 Jan 2014
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 Comments
Sean de Wolski
on 9 Jan 2014
I don't have time right now. But this has certainly been demonstrated here before.
Is probably a good start
More Answers (0)
See Also
Categories
Find more on Migrate GUIDE Apps in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!