Info

此问题已关闭。 请重新打开它进行编辑或回答。

Timer object to rquest data from txt file

2 次查看(过去 30 天)
Camilo
Camilo 2016-2-22
关闭: MATLAB Answer Bot 2021-8-20
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 个评论
jgg
jgg 2016-2-22
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

回答(0 个)

此问题已关闭。

Community Treasure Hunt

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

Start Hunting!

Translated by