How to extract specific data from a txt file
88 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hi there!
I have a txt file that contains lines starting in either U4 or U6. I want to filter out all the lines with U4 so I'm left with only the ones that contain U6. How would I go about that?
Thanks in advance!
0 Commenti
Risposte (2)
Star Strider
il 23 Giu 2023
% type('Niskin-Logger-Sample.txt')
opts = detectImportOptions('Niskin-Logger-Sample.txt', 'Delimiter',{' '});
opts = setvaropts(opts, 'Var3', 'InputFormat','MM/dd/uuuu'); % Guessing The Date Format
T1 = readtable('Niskin-Logger-Sample.txt', 'Delimiter',{' '});
T2 = readtable('Niskin-Logger-Sample.txt', 'HeaderLines',50)
[UVar1,~,ix] = unique(T2.Var1);
Um = accumarray(ix, (1:numel(ix)).', [], @(x){T2(x,:)})
U6 = Um{2}
U6Var2NotNaN = U6(~isnan(U6.Var2),:)
NrVar2NaN = nnz(isnan(U6.Var2))
So ‘Var2’ (whatever it is) has only NaN values for the entire ‘U6’ table.
.
0 Commenti
Mayur
il 23 Giu 2023
Hi Sydney!
I understand that you want to extract specific lines from a .txt file, here particularly lines starting with 'U6'. You can use the following code snippet:
fid = fopen('Niskin-Logger-Sample.txt', 'r');
data = textscan(fid, '%s', 'Delimiter', '\n');
fclose(fid);
u6_lines = data{1}(startsWith(data{1}, 'U6'));
disp(u6_lines);
0 Commenti
Vedere anche
Categorie
Scopri di più su Large Files and Big Data in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!