Unable to extract data between two lines from a text file of below format

2 次查看(过去 30 天)
Text file is of below format
09:14.414] GPIB:ROUT:GPRF:MEAS:RFS:CONN RF1C
[09:14.416] ---Tx RF verify Measurement Results---
[09:14.417] LTE Path 47 Band 13 Not CA Frequency 180.0 Expected Power 23.0 50RB_Full RB Start Pos 0 BW 10.0 MHz Mod QPSK Tx Power 22.95 Limits 22 to 24 [dBm] Passed
[09:14.417] LTE Path 47 Band 14 Not CA Frequency 181.0 Expected Power 23.0 50RB_Full RB Start Pos 0 BW 10.0 MHz Mod QPSK EVM RMS 3.41 Limit 6 [%] Passed
[09:14.418] LTE Path 47 Band 15 Not CA Frequency 182.0 Expected Power 23.0 50RB_Full RB Start Pos 0 BW 10.0 MHz Mod QPSK EVM Peak 22.05 Limit 30 [%] Passed
[09:16.405] ---Performing Tx RF verify ended---
[09:17.388] FAIL: RS-RFV_Tx PostProcess
[09:17.392] --- End calibration ---
[09:17.392] Serial TX 'at@3,711 xns:!<\r><\n>'
Below is the code I have written to extract necessary data into an array. Index value( idx1 and idx2) it has shown is correct but data value is blank it didnt show any data in that variable.
fid = fopen('2018-09-26_11.08.16_18.26_trace_0.txt','r');
S = textscan(fid,'%s','Delimiter','\n');
S = S{1};
fclose(fid);
idxS1 = strfind(S, '---Tx RF verify Measurement Results---');
idx1 = find(not(cellfun('isempty', idxS1)));
idxS2 = strfind(S, '---Performing Tx RF verify ended---');
idx2 = find(not(cellfun('isempty', idxS2)));
data = cell2mat(cellfun(@str2num,S(idx1+1:idx2-1),'un',0)) ;
Can you pleas help to extract data between '---Tx RF verify Measurement Results---' and '---Performing Tx RF verify ended---' into an array
Also after that I need to get Tx power in one column and EVM RMS in one column

回答(2 个)

Michael Madelaire
I do not know how you want the data. But you can very simply use
fgetl(fid)
to get a single line.
fid = fopen('example.txt');
fgetl(fid); fgetl(fid);
data = {};
for i = 1:3
tline = fgetl(fid);
data{i} = split(tline);
end
then you have a array containing each line split by a space-delimiter.
disp(data{1}); % to print a line
disp(data{1}(1)); % to show the first element in the first line
  4 个评论
N/A
N/A 2019-1-3
I tried running the code. Now its showing array size instead of actual data in the variable data as shown in the attached figure.
Michael Madelaire
编辑:Michael Madelaire 2019-1-3
No, no it does not. Let's go back to the first piece of code.
"then you have a array containing each line split by a space-delimiter.
disp(data{1}); % to print a line
disp(data{1}(1)); % to show the first element in the first line
"
Now the data might not be in the format that you want. So let's go to my most resent comment.
"Next I do not understand what you means with extract data. That implies getting it in a specific format, which you have not given."
HOW DO YOU WANT THE DATA!!....

请先登录,再进行评论。


N/A
N/A 2019-1-3
I have attached the text file which we are giving as input and an excel that will give an idea on the format how array need to be. Hoping this would give more clarity. Let me know if it is still not clear.
  1 个评论
Michael Madelaire
Yes it is more clear. But it is the third time you bring up more detail, making prior answers (that did what you asked for) waste of time.
I am out.
Best of luck.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 File Operations 的更多信息

标签

尚未输入任何标签。

Community Treasure Hunt

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

Start Hunting!

Translated by