UPDATE DATA every 5 sec
조회 수: 1 (최근 30일)
이전 댓글 표시
I have a ekg sensor attached which reads the heart rate and i have written the code to display Beats per minute based on it. How can add code so that it reads data every 5 seconds and save BPM.
댓글 수: 2
mbvoyager
2018년 9월 6일
편집: mbvoyager
2018년 9월 6일
I do not really understand your issue.
But a very quick and very very dirty solution could be to use a for or while loop and input the function pause or wait.
This is far from exact in timing but it can limit the readings of your data to a certain coarse interval.
In general it might be a good idea if you look into the usage of timers. Can be found in: timer class.
답변 (1개)
mbvoyager
2018년 9월 6일
Look into the examples of
With the timer class it is possible to call a function in certain time intervals.
Here is a minimal working example exactly from the help page of the timer class:
t = timer;
t.StartFcn = @(~,thisEvent)disp([thisEvent.Type ' executed '...
datestr(thisEvent.Data.time,'dd-mmm-yyyy HH:MM:SS.FFF')]);
t.TimerFcn = @(~,thisEvent)disp([thisEvent.Type ' executed '...
datestr(thisEvent.Data.time,'dd-mmm-yyyy HH:MM:SS.FFF')]);
t.StopFcn = @(~,thisEvent)disp([thisEvent.Type ' executed '...
datestr(thisEvent.Data.time,'dd-mmm-yyyy HH:MM:SS.FFF')]);
t.Period = 5; % 5 seconds interval executing TimerFcn
t.TasksToExecute = 3; % 3 total calls excecuting TimerFcn
t.ExecutionMode = 'fixedRate';
start(t)
The output will be:
StartFcn executed 06-Sep-2018 14:15:03.161
TimerFcn executed 06-Sep-2018 14:15:03.161
TimerFcn executed 06-Sep-2018 14:15:05.162
TimerFcn executed 06-Sep-2018 14:15:07.161
StopFcn executed 06-Sep-2018 14:15:07.168
After that to delete the timer object
delete(t)
I hope this can help you.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!