Best way to parse text file
Show older comments
I am trying to write some code to parse large text files of weather data. The formatting of the text file is broken into blocks, by state. The data I'm working with is here
Within each block (state), the .txt file formatting is consistent and should be fairly straight forward to parse. However, each block has an inconsistent number of rows (varying amount of reporting weather stations across states, and time) it not clear to me that each block is delimited from one another. I'm trying to get ultimately arrive at an N x 3 matrix, with columns for state, county, and total snowfall.
I'm not sure which functions are best for this purpose. Can someone point me in the right direction? I don't know where to start....
Thanks
5 Comments
per isakson
on 7 Apr 2015
Edited: per isakson
on 7 Apr 2015
- where does BLMA1 belong? It's StnID and not all stations have a StnID value. That makes things a "little" more complicated.
- the columns of the data block are separated by one or more spaces?
- are the widths of the columns known?

Jesse Program
on 8 Apr 2015
Jesse Program
on 10 Apr 2015
per isakson
on 10 Apr 2015
Edited: per isakson
on 10 Apr 2015
Yes, but there was a major "issue" and no time to fix it. Now, I have posted a new code.
Accepted Answer
More Answers (0)
Categories
Find more on Data Import and Export 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!