Borrar filtros
Borrar filtros

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

3 visualizaciones (últimos 30 días)
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!

Respuesta aceptada

KSSV
KSSV el 10 de Nov. de 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) ;

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by