UPDATE DATA every 5 sec

1 visualización (últimos 30 días)
Eeman Fatima
Eeman Fatima el 6 de Sept. de 2018
Respondida: mbvoyager el 6 de Sept. de 2018
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 comentarios
mbvoyager
mbvoyager el 6 de Sept. de 2018
Editada: mbvoyager el 6 de Sept. de 2018
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 el 6 de Sept. de 2018
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.

Iniciar sesión para comentar.

Respuestas (1)

mbvoyager
mbvoyager el 6 de Sept. de 2018
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.

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by