Setting timer to repeat a dos command

hi there!
I 've got a little problem with scripts like this one:
t = timer('TimerFcn', 'stat=false','StartDelay',10);
start(t)
stat=true;
while(stat==true)
dos('dir')
datetime
pause(10)
end
stop(t)
delete(t)
It works one time only or keep repeating ad infinitum. I'm using R2016a.

댓글 수: 3

Geoff Hayes
Geoff Hayes 2020년 2월 5일
Gabriel - please describe the intent of the above code. Are you using the timer so that when the callback is fired, you will exit the while loop (because stat is now false)? I see that your above code is based on the example from use a MATLAB timer object. Given that the timer delay is ten seconds and the pause in your code is for ten seconds, then it might make sense that it would only work one time (i.e. one iteration of the loop). When you say repeating ad infinitum does this happen when you remove the pause?
Gabriel Silva
Gabriel Silva 2020년 2월 5일
Well, Geoff, it's the same timer example, but using some dos commands. I do not remove the pause. I hope this particular script to repeat 'dir' 10 times, but it gives me only one. I put a pause of 30 seconds, but then I reduce it to 10. Not working, anyway.
Geoff Hayes
Geoff Hayes 2020년 2월 7일
Gabriel - why not try a pause of 0.5? or even 1.0 seconds? I think that because you are pausing for ten seconds and because your timer expires after ten seconds (due to the StartDelay property being 10), you will only ever see dir be called once...

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

답변 (0개)

카테고리

도움말 센터File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

제품

릴리스

R2016a

태그

질문:

2020년 2월 5일

댓글:

2020년 2월 7일

Community Treasure Hunt

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

Start Hunting!

Translated by