How to read the header lines in a text file?

7 views (last 30 days)
Vishnu
Vishnu on 25 Sep 2014
Commented: Adam on 26 Sep 2014
I have a text file with an header lines contains names and numbers. There is a columned data is there below the header lines. how to read the header line? also i wants to read the data separately also? how to write commands for it?
  5 Comments
dpb
dpb on 26 Sep 2014
You're not going out of your way to make things easy for somebody who has no klew about the problem...answers/help can only be as good as the input provided.
How many physical records are actually in the above and where, specifically are the record beginnings/endings? What, other than the two obvious date/times are the other values of interest? It could be presumed the place is the first string, perhaps, or is it some set of coordinates from the other numeric values? Another guess is that, perhaps the final "02" on the end of the first (or second record if there is a break as shown) is the number of channels in the file? Do you have to deal with more than the present case of 2?
There are examples in
doc textscan
of reading mixed data formats
Adam
Adam on 26 Sep 2014
If you really want some "fun" you can use regexp to extract the information you want having read in a header, but your example still does not define exactly what a header is in order to separate it out from everything else when reading the data in.
I spent most of last week messing around with regexp for the first time to extract the information I wanted from such a text file, but I was working from a clearly defined specification document that contained an example file so that I could test my regular expressions against all the valid cases. Without that clear definition it is rather difficult!

Sign in to comment.

Answers (1)

Sean de Wolski
Sean de Wolski on 25 Sep 2014
Also look at just using the import tool to import them as a cell array:
Home Tab -> Import Data -> Select your file

Community Treasure Hunt

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

Start Hunting!