How to read from LOG file
4 次查看(过去 30 天)
显示 更早的评论
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 个评论
Sepehr Ariaei
2021-6-24
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
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Import and Export 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!