Reading text file in Matlab

5 visualizaciones (últimos 30 días)
gd
gd el 19 de Feb. de 2021
Editada: gd el 21 de Feb. de 2021
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!

Respuesta aceptada

Cris LaPierre
Cris LaPierre el 20 de Feb. de 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.

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