How to read from LOG file
4 views (last 30 days)
Show older comments
Hello all,
After trying a lot with 'fopen' and 'textscan' here I am posting my issue.
I have text file as attached. My goal is to read numerical values of 'HLP' and 'PSC' in saperate arrays and also the 1016 complex values which comes after 'Accum Len 1016' in another array.
since text file is updating in real time in windows 10, the above three arrays also needs to be read again and again.
After each reading I need to perform some calculations and plot the data.
After ploting and before reading new values I also need to store the previus data each time(But this is otional as of now).
here is my code:
f1 = fullfile(' file name ');
fid1 = fopen(f1);
while ~feof(fid1)
tline1 = fgetl(fid1);
if contains (tline1,'HLP')
HLP1 = textscan(tline1,'%s',7,'Delimiter','(,)');
% HLP1 = textscan(tline1,'HLP=%n',7,'Delimiter','(,)');
% Here some calculations
else if contains (tline1,'Accum Len')
Acc1 = double(cell2mat(textscan(fid1,'%d16 %d16',1016,'Delimiter',',')));
Abs_Acc1=abs(Acc1);
Mag1 = max(Abs_Acc1,[],2) + 1/4*min(Abs_Acc1,[],2);
% Here some calculations
else if contains (tline1,'PSC')
PSC1 = double(cell2mat(textscan(tline1,'PSC=%u16',7,'Delimiter','(,)')));
% Here some calculations
end
end
end
end
fclose(fid1);
2 Comments
Sepehr Ariaei
on 24 Jun 2021
I have the same exact issue. I have a log file which is updating. I could not resolve it. Do you have anything now that could help me?
Thanks in advance
Sepehr
Answers (0)
See Also
Categories
Find more on Data Import and Export in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!