The function drawnow
causes figure windows and their children to update, and flushes the system event queue. Any callbacks generated by incoming events (e.g., mouse or key events) are dispatched before
drawnowreturns.
I have the following script:
clear all;
clc;
t = timer;
set(t, 'Period', 1);
set(t, 'ExecutionMode', 'fixedSpacing');
set(t, 'TimerFcn', @(event, data) disp('Timer rollover!'));
start(t);
while(1)
%# do something interesting
drawnow;
end
With the drawnow in place, the timer event will occur every second. Without it, no callback function occurs because the while loop is “blocking”.
My questions:
1) Is there a way to flush the queue without updating figure windows?
2) When we say “flush the event queue”, do we mean “execute everything in the event queue”, “execute what’s next in the queue and drop everything else out of the queue”, or something else entirely?
I have multiple callback functions from multiple separate timers happening in the background of my program. Not having one of these callbacks executing is not an option for me. I just wanted to clarify and make sure I’m doing the right thing.
1) Not to my knowledge – at least, I believe the only way to flush the queue is to call
drawnow. Depending on what you mean by ‘update figure windows’, you may be able to prevent drawnow from having an undesirable effect (e.g. by removing data sources before calling drawnow).2) I can’t test this right now, but based on how I’ve used it before, and the description you gave above, I’m pretty sure it’s “execute everything in the queue”.
Another thing I’m not sure about is whether you need
while 1; drawnow– don’t events work as you would expect if you just end the script afterstart(t)? I thoughtdrawnowwas only necessary if you are doing some other stuff e.g. inside the while loop.