Reading txt file with multiple headers and non-uniform data blocks
5 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
KSSV
on 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 Comments
More Answers (0)
See Also
Categories
Find more on Text Files in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!