Clear Filters
Clear Filters

Info

This question is closed. Reopen it to edit or answer.

Timer object to rquest data from txt file

1 view (last 30 days)
Camilo
Camilo on 22 Feb 2016
Closed: MATLAB Answer Bot on 20 Aug 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 Comment
jgg
jgg on 22 Feb 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

Answers (0)

This question is closed.

Community Treasure Hunt

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

Start Hunting!