필터 지우기
필터 지우기

UPDATE DATA every 5 sec

조회 수: 13 (최근 30일)
Eeman Fatima
Eeman Fatima 2018년 9월 6일
답변: mbvoyager 2018년 9월 6일
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
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.
As seen in: function 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.
Eeman Fatima
Eeman Fatima 2018년 9월 6일
I have this code which reads the data from the sensor and then calculates beat per minuts is there anyway i can make so that it automatically updates data every5 seconds and save the bpm for each time.

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

답변 (1개)

mbvoyager
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.

카테고리

Help CenterFile Exchange에서 Data Type Identification에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by