Effacer les filtres
Effacer les filtres

Reading txt file with multiple headers and non-uniform data blocks

3 vues (au cours des 30 derniers jours)
Bruno Rodriguez
Bruno Rodriguez le 10 Nov 2017
Réponse apportée : KSSV le 10 Nov 2017
All,
I'm trying to read in a large text file that has several headers (always one line, different headers but all begin with letters "AL"). I've seen a few suggestions online, but these only apply to files with equally-sized blocks of data. Unfortunately, the size of such blocks varies every time for this particular file. Additionally, I want to keep each block separate from the others.
I've attached the file in a zipped folder for reference.
Any suggestions?
Thanks!

Réponse acceptée

KSSV
KSSV le 10 Nov 2017
fid = fopen('hurdat2.txt','r') ;
S = textscan(fid,'%s','delimiter','\n') ;
S = S{1} ;
fclose(fid) ;
%%GEt lines wih AL
idx = find(contains(S,'AL')) ;
iwant = cell(length(idx),1) ;
for i = 1:length(idx)-1
iwant{i} = S(idx(i)+1:idx(i+1)-1) ;
end
iwant{end} = S(idx(end)+1:end) ;

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by