Update: I found that the callback does execute, but the text displayed by the callback ends up in the Command Window and not the output panel of the Live Script. The text displayed before the callback shows up in the output panel.
Timer callback example not working
4 次查看(过去 30 天)
显示 更早的评论
I would like to create a timer with a callback, so I tried the example code from the "Schedule Command Execution Using Timer" documentation page. When I copy+paste the example into a live script and run it, the callback never executes.
回答(1 个)
YASSINE
2023-8-30
编辑:YASSINE
2023-8-30
Hi, the text is not showing because the timer object callback function is not attached to the live script. You can use "eval(t.TimerFcn)" as a workaround to display text in the live script command window.
t = timer('TimerFcn', 'stat=false; disp(''Timer!'')',...
'StartDelay',10);
start(t)
stat=true;
while(stat==true)
disp('.')
pause(1)
end
eval(t.TimerFcn)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!