How to execute at a specific time?
12 ビュー (過去 30 日間)
古いコメントを表示
Hello, I wish to run a script every 0.3333 seconds. The time it takes the computer to run it is much less than that.
How would I go about doing this? I tried things like
tic;
i= 1;
while i == 1
if rem(toc, 0.3333) == 0
*run script*
end
but using "while" means it's forever Busy.
0 件のコメント
採用された回答
Paulo Silva
2011 年 8 月 15 日
Replace 'disp(''Hello'')' by your function with the symbol @ before it, example @MyFunction
t = timer('TimerFcn','disp(''Hello'')',...
'ExecutionMode','fixedRate','Period',0.3333);
start(t)
%stop(t)
%delete(t)
Before you ask why you can't do other things while the timer is running, MATLAB only executes one function at a specific time. It will happen almost the same like you see in your loop, the only difference is the time that remains after executing your function and the next function call by the timer. I hope that your function is really fast because if it isn't you will have problems, MATLAB might crash.
0 件のコメント
その他の回答 (1 件)
参考
カテゴリ
Help Center および File Exchange で Symbolic Math Toolbox についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!