How to properly use fopen/ fclose function for live streaming data

I tried to use the fopen and fclose functions to read real live data (updated every 60s) from eight different csv files - read in a loop. Sometimes there were some delays in data transferred from the server to the csv file. Every now and the this error will pop-up e.g. :
I am not sure why but I guess it seems that matlab extracts the data while the data being downloaded..
Wonder if anyone has any idea on how to solve this problem?
Thanks.
Error using datetime (line 640)
Unable to convert the text to datetime using the format 'yyyy.MM.dd HH:mm:ss'.
Error in RealTime_Process (line 50)
t = datetime(d,'InputFormat','yyyy.MM.dd HH:mm:ss');
for q=1:1000
for k=1:8
PathName = 'C:\Users\Me\Terminal\F762D69EEEA9B4430D7F17C82167C844\MQL5\Files\';
File=InputList{k,1};
DataFile = fullfile(PathName, File);
h=fopen(DataFile);
if h==-1
path='C:\Users\Me\F762D69EEEA9B4430D7F17C82167C844\MQL5\Files\';
else
load(DataFile);
data=readtable(DataFile);
fclose(h);
% some data processing over here %
.
.
end
pause(60)
end

1 commentaire

What kind of data are you trying to read? The error seems to suggest that there is some datetime data and the format does not match the 'InputFormat' that you specified.
Also, I'm not sure if I completely understand your workflow, but if you are just reading csv file, then I dont think you need those fopen/fclose calls, simply calling readtable on that file should be sufficient.

Connectez-vous pour commenter.

Réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by