parallel timers not executing as expected
Afficher commentaires plus anciens
I am trying to run two parallel timers. Below is a minimal example.
I would expect (or wish) that timerCallback2 is executed when timerCallback1 is in pause mode. But the function seems to be blocking. I also tried to add some drawnow calls.
Is there any way to execute multiple timer callbacks while another is still running, or is this intended behavior? Does MATLAB not process the event queue while another event is still running? Or are there different event queues for timer events and GUI events?
Thank you for your help!
timer1 = timer(Name="timer1", ExecutionMode="fixedSpacing", BusyMode="queue", TimerFcn=@timerCallback1, TasksToExecute=3, Period=1);
start(timer1)
timer2 = timer(Name="timer2", ExecutionMode="fixedSpacing", BusyMode="queue", TimerFcn=@timerCallback2, TasksToExecute=30, Period=0.1);
start(timer2)
function timerCallback1(~,~)
disp("start T1...")
pause(2)
disp("end T1...")
end
function timerCallback2(~, ~)
disp(" start T2...")
pause(0.05)
disp(" end T2...")
end
%% Output is:
% start T1...
% end T1...
% start T2...
% end T2...
% start T2...
% end T2...
% start T2...
% end T2...
% start T2...
% end T2...
% start T2...
% end T2...
% start T2...
% end T2...
% start T2...
% end T2...
% start T1...
% end T1...
% start T2...
% end T2...
% start T2...
% and so on....
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Parallel for-Loops (parfor) dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!