Extract Data from .txt File

3 次查看(过去 30 天)
Hi, someone can help me extract data from this .txt File? I'm interested in extracting the numeric values of "PeakEvm" that appears in the file.
I have tried to use textscan, pattern, extract and extractBetween but they are useless for this task.

采纳的回答

C B
C B 2021-10-27
编辑:C B 2021-10-27
alltext = fileread('Datos_SSB_624_MHz_7_dB.txt');
% extract data between {"peakEvm": and },
allmatches = regexp(alltext,'(?<={"peakEvm":).*?(?=},)','match')
allmatches = 1×16 cell array
{'{"percent":12.372359275817871,"subcarrierNumber":753,"symbolNumber":5'} {'{"percent":13.889286994934082,"subcarrierNumber":522,"symbolNumber":3'} {'{"percent":9.418230056762695,"subcarrierNumber":574,"symbolNumber":2'} {'{"percent":9.726147651672363,"subcarrierNumber":694,"symbolNumber":4'} {'{"percent":13.805439949035645,"subcarrierNumber":517,"symbolNumber":11'} {'{"percent":14.057321548461914,"subcarrierNumber":750,"symbolNumber":9'} {'{"percent":8.600445747375488,"subcarrierNumber":696,"symbolNumber":8'} {'{"percent":8.529023170471191,"subcarrierNumber":698,"symbolNumber":10'} {'{"percent":14.28252124786377,"subcarrierNumber":517,"symbolNumber":19'} {'{"percent":16.036340713500977,"subcarrierNumber":516,"symbolNumber":18'} {'{"percent":8.51211929321289,"subcarrierNumber":579,"symbolNumber":16'} {'{"percent":8.950516700744629,"subcarrierNumber":695,"symbolNumber":18'} {'{"percent":14.643827438354492,"subcarrierNumber":517,"symbolNumber":25'} {'{"percent":15.098423957824707,"subcarrierNumber":519,"symbolNumber":25'} {'{"percent":9.247054100036621,"subcarrierNumber":573,"symbolNumber":22'} {'{"percent":9.152688980102539,"subcarrierNumber":696,"symbolNumber":24'}
% extract data between {"percent": and ,
num1 = regexp(allmatches,'(?<={"percent":).*?(?=,)','match');
% extract data between "subcarrierNumber": and ,
num2 = regexp(allmatches,'(?<="subcarrierNumber":).*?(?=,)','match');
% extract data between "symbolNumber": and end
num3 = regexp(allmatches,'(?<="symbolNumber":).*?(?=)','match');
vertcat(num1{:})
ans = 16×1 cell array
{'12.372359275817871'} {'13.889286994934082'} {'9.418230056762695' } {'9.726147651672363' } {'13.805439949035645'} {'14.057321548461914'} {'8.600445747375488' } {'8.529023170471191' } {'14.28252124786377' } {'16.036340713500977'} {'8.51211929321289' } {'8.950516700744629' } {'14.643827438354492'} {'15.098423957824707'} {'9.247054100036621' } {'9.152688980102539' }
vertcat(num2{:})
ans = 16×1 cell array
{'753'} {'522'} {'574'} {'694'} {'517'} {'750'} {'696'} {'698'} {'517'} {'516'} {'579'} {'695'} {'517'} {'519'} {'573'} {'696'}
vertcat(num3{:})
ans = 16×1 cell array
{'5'} {'3'} {'2'} {'4'} {'1'} {'9'} {'8'} {'1'} {'1'} {'1'} {'1'} {'1'} {'2'} {'2'} {'2'} {'2'}

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Import and Export 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by