Reading text file in Matlab
1 view (last 30 days)
Show older comments
Hi all,
I'm having some trouble extracting data from a textfile. The files I'm working with have 100 lines of header information, which I have successfully extracted. After the header, there is a date (format 'yyyymmdd.HHMMss'), followed by two lines (describing the factor to multiply data by) and then 31 rows of numbers. Factor lines and 31 rows of numbers are repeated 5 times (1 per location), and then the next time step begins with the new date, the factor lines, and 31 rows of numbers repeated 5 times. I.e., For each time step, there are 5 blocks of numerical data (one per location) and associated factor lines.
The goal: search the file for the generic date format, extract the two lines below it (one is 'FACTOR', the next is a number %f), and then extract the subsequent 31 lines containing numbers into a cell. I then wish to skip the 4 remaining blocks of text and head to the next date, extract the first block into next cell element, etc, in that I only want data from one location. This process must be repeated until the end of the file.
The blocks of numbers are 31 rows x 48 columns.
Please let me know if more information would be helpful in solving this. I am not a beginner to Matlab, however I am a beginner in processing .txt files, so any guidance is greatly appreciated!
0 Comments
Accepted Answer
Cris LaPierre
on 20 Feb 2021
I wonder if it would make more sense to try to use the OpenEarthtools toolbox rather than try to create your own input function. It appears to have been written to work with SWAN input and output files.
0 Comments
More Answers (0)
See Also
Categories
Find more on Language Support 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!