Timer callback example not working

조회 수: 7 (최근 30일)
Scott
Scott 2023년 8월 28일
댓글: Scott 2023년 8월 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.
  댓글 수: 2
Scott
Scott 2023년 8월 29일
이동: Voss 2023년 8월 29일
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.
Scott
Scott 2023년 8월 29일
이동: Voss 2023년 8월 29일
This did not fully answer the problem. Why does the display text of the callback show up in the command window instead of the output pane? The display text from the other part of the code shows in the output pane as expected.

댓글을 달려면 로그인하십시오.

답변 (1개)

YASSINE
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)
  댓글 수: 1
Scott
Scott 2023년 8월 30일
Thanks Yassine. So this code essentially runs the callback a second time after the while loop, to display the text in the output pane, while the actual callback has run in the background. That's an ok workaround if all that matters is what shows up in the output pane, but I don't think it's generally very practical. Is there no way to attach the callback to the live script so that it works as expected?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Code Execution에 대해 자세히 알아보기

태그

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by