필터 지우기
필터 지우기

I need to make a continuous timer

조회 수: 2 (최근 30일)
Javier
Javier 2015년 11월 9일
답변: Guillaume 2015년 11월 9일
I need to make a continuous timer to be used with a Data Acquisition program. I am saving the acquired data every minute, and my timer will occur every hour, so I cannot use pause instead of a timer because I will not be able to save my data. I have been able to create timers that activate on a periodic basis, but they have a finite number of periods. I am looking to make a timer that runs indefinitely. I am using the core Matlab program to acquire my data, this program is in an .m file.
  댓글 수: 1
Guillaume
Guillaume 2015년 11월 9일
" but they have a finite number of periods"
As far as I know, this is not true.

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

채택된 답변

Guillaume
Guillaume 2015년 11월 9일
As far as I know, matlab timers are not restricted to a finite number of periods.
If a standard matlab timer is not suitable and you're on Windows, you can always use a .Net Timer:
period = 5000; %in milliseconds
nettimer = System.Timers.Timer(period);
nettimer.AutoReset = true; %true by default anyway
timerlistener = addlistener(nettimer, 'Elapsed', @(~, ~) disp('Hello'));
nettimer.Enabled = true; %start timer
I would still recommend using a matlab timer.

추가 답변 (1개)

TastyPastry
TastyPastry 2015년 11월 9일
If you want to measure performance in real time (i.e. seconds), you can use the functions tic() and toc() which start and read the timer, respectively. Call tic() again to reset the timer. Alternatively, there are functions timeit() and cputime() depending on what you're trying to time.
  댓글 수: 1
Javier
Javier 2015년 11월 9일
Tic and toc are great to get elapsed time. I have tried them with pause to get elapsed time between pauses, but in this occasion I am looking to run a function every hour indefinitely without using pause. My problem is not with reading time every hour, but with executing a timer every hour on a loop without using pause. I can create the timer, but the timer ends at some point, I would like to know how to create a timer that never ends.

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

카테고리

Help CenterFile Exchange에서 Introduction to Installation and Licensing에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by