textread formatting help

6 views (last 30 days)
Leigh
Leigh on 13 Sep 2011
I have an ascii file which contains hourly sea level data in the following format:
siteid Year Month Day Hour Level Level Level Level... etc.
cn 1965 1 1 0000-9999-9999-9999-9999-9999-9999-9999-9999-9999-9999-9999-9999
Where the hour is either 1200 or 0000, and the following values are the hourly tidal level for the 12 hour period. I'm having trouble extracting the data as there are no delimiters, but the values are restrained to their own columns.
Example, for the 11th of december 1969. There is no delimiters between year, month and day.
cn 19691211 0000 170 410 720 960 1020 1050 990 870 810 810 840 1020
Is there a way to set the format so matlab reads the value that is present in a certain column range? Like columns 8:11 which represent year. Any help would be greatly appreciated.

Accepted Answer

per isakson
per isakson on 13 Sep 2011
Do you know the exact format, i.e. the length of each field? I assume you do!
Read the full line as a string
buf = textscan( fid, '%s', 'delimiter', sprintf( '\n' ) );
next extract the columns
col1 = buf{ :, ix1:ix2 };
something like this. I leave the exact handling of the cell array. And last convert to numeric.
- per
  1 Comment
Leigh
Leigh on 13 Sep 2011
Thanks for the quick reply!
Did the job :)

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!