Effacer les filtres
Effacer les filtres

Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

Timer object to rquest data from txt file

2 vues (au cours des 30 derniers jours)
Camilo
Camilo le 22 Fév 2016
Clôturé : MATLAB Answer Bot le 20 Août 2021
Hello everyone
I want to fix my problem. I am trying to request data from a txt file generated every 1 minute with new data. The code I am using is:
% Matlab code
function time_object
%Creating timer object
t = timer('TimerFcn',@request_data,'ExecutionMode','fixedRate','Period',1,'TasksToExecute',Inf);
start(t);
function request_data
path = 'C:\Users\fullfilename.txt';
data = dlmread(path, ';', 2, 2);
value = data(:,3);
fprintg('Data: %f\n',value)
end
% End of my code
I'd like to print new data every minute when my txt file is generated but nothing happens at the moment. Someone knows how is the correct wat to define a timer object? ... if it is possible I'd like to run time at specific time as well.
I've seen some examples using datenow to upload time but I do not how to do it.
Thanks for your support. Camilo
  1 commentaire
jgg
jgg le 22 Fév 2016
I'm unclear what the issue is? This seems to work well for me:
t = timer('BusyMode','drop','ExecutionMode','fixedRate', 'Period', 10,'StartFcn',@(varargin)(tic),'TimerFcn',@(varargin)(toc))
You'd want your period to be 60. I also see this would handle your starting time problem: http://www.mathworks.com/help/matlab/ref/timer.startat.html

Réponses (0)

Cette question est clôturée.

Community Treasure Hunt

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

Start Hunting!

Translated by