Reading txt file with multiple headers and non-uniform data blocks
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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!
0 commentaires
Réponse acceptée
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) ;
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Text Files dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!