Execute a command after a delay

조회 수: 15 (최근 30일)
Leo Simon
Leo Simon 2016년 6월 1일
댓글: Antonio Del Negro 2018년 10월 10일
Based on this thread I'm not optimistic, but thought I'd give it a try. I'd really like to be able to execute a command after a delay, e.g., run a script that says
pause(10); disp('Hullo')
but have the program continue during the pause time, so that code lines can be executed before the disp command. In linux, one could do this by "backgrounding" the command string. Maybe there's some fancy undocumented way of doing this in matlab? If not it would be a great addition.

채택된 답변

Sean de Wolski
Sean de Wolski 2016년 6월 1일
Use a timer with a start delay.
T = timer('StartDelay',10,'TimerFcn',@(src,evt)disp('Hello World'));
start(T)
surf(peaks) % something running while timer waiting
And for more info:
doc timer
  댓글 수: 2
Leo Simon
Leo Simon 2016년 6월 1일
Fabulous thanks, that will be tremendously useful
Antonio Del Negro
Antonio Del Negro 2018년 10월 10일
what if I'm running the same command inside a MATLAB function block of Simulink? I'm saying this because I tried doing so and the following appears:
"The Timer class does not support code generation"
Any alternative for the case of a matlab function block from simulink? I've been looking all day. Thanks!

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by