필터 지우기
필터 지우기

Log file Plot using Matlab in Realtime

조회 수: 9 (최근 30일)
TAPAN PATEL
TAPAN PATEL 2019년 10월 7일
댓글: TAPAN PATEL 2019년 10월 8일
Software generates log files contains complex values, a 16-bit real integer and a 16-bit imaginary integer which is shown in text file starting from line 13.
Before line 13 general information which is not needed.
How can I get that data in to matlab and plot in real time?
I can not attach log file so I converted and attached it into *.txt file
  댓글 수: 1
TAPAN PATEL
TAPAN PATEL 2019년 10월 8일
thank you so much and now this is how my code looks like:
fid = fopen('20191008-155724_DecaWaveAllAccum.log');
S = [ ];
Count = 0;
while ~feof(fid)
tline = fgetl(fid);
if contains (tline,'Accum Len')
Count = Count + 1;
s = textscan(fid,'%d16 %d16',1016,'Delimiter',',');
real = s{1};
Img = s{2};
ss = cell2mat(s);
sss = double(ss);
S = [S;sss];
end
end
fclose(fid);
with updating log file my count is not updating automatically. I need to run the code again in order to update the count. But I need it to be in REALTIME. Is there any other way to do this?

댓글을 달려면 로그인하십시오.

답변 (1개)

Walter Roberson
Walter Roberson 2019년 10월 7일
You will need to fopen() the file for reading.
Start an indefinite loop to read blocks
WIth the indefinite loop, start a second oop using fgetl() and looking for lines that start with 'Accum Len'. If the line does not start with that, loop back to fgetl(). If the line does start with it, then parse the line to get the number; that will be the number of samples to read.
Now use textscan() with appropriate format and delimiter ',' . Right after the format parameter, pass in the number of samples (e.g., 1016). cell2mat() the textscan results, and proceed to plot or store the information .
After that you loop back in the indefinite loop to read more blocks -- you would be back to the mode of skipping lines until you get to Accum Len.
  댓글 수: 3
Walter Roberson
Walter Roberson 2019년 10월 7일
You mention that you want to do this in "Real Time". Is it correct that some other program will be writing more data to the end of the file while the MATLAB program is running to plot the data? If so then there are complications around reaching the end of file; unless there is some kind of protocol to signal between the two processes, at any one time that the MATLAB routine goes to look at the file, the other routine might be in the middle of reading the file. If you are using MS Windows that potentially mandatory locking could cause problems too.
TAPAN PATEL
TAPAN PATEL 2019년 10월 8일
Hello Walter Roberson,
firstly, many thanks your reply.
So in detail: The log file is continuously updating by one software in MS windows platform (which is getting data via USB port from and CIRCUIT board connected to it). This data comming from USB port is accordingly procressed by PC software and log file is created and getting updated unless user select the stop button.
After log file started getting data, I should start MATLAB program manually to fetch data from it. I understand I need some protocole that control speed of MATLAB program that does not overtake the speed of updating log file. Is there any other way to do this?
and about 'mandatory file locking', for that I simply tried below code while log file was in updaing mode and it succefully fetch first 1016 data.
fid = fopen('filename.log');
s = textscan(fid,'%d16 %d16','Delimiter',',','headerlines',12);
fclose(fid);
and I have as result :
s =
1×2 cell array
{1016×1 int16} {1016×1 int16}
Regards,
Tapan Patel

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Device Characteristics Assessment에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by