How to read the header lines in a text file?

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

Adam
Adam on 25 Sep 2014
Edited: Adam on 25 Sep 2014
Is the data not in some standard defined format? Format specifications for data that is expected to be read in by some other program usually includes strict rules for how many header lines there are or some special character that either represents a header line or the end of the header/start of the data
Need an example of the file to have any specific formatting help; in general
doc textscan
Actually headers are in the form like this
TRIVANDRUM 25/09/2014 06:58:31 25/09/2014 06:59:01 0180 0086.3 0026.5 00
0000000 0020 0000600 0020 02
1 0 2 04000 1 0000 17.50 00000.o 0 0 00 000 12 000600 0.100 BT0
1 0 2 04000 1 0000 17.50 00000.p 0 0 00 000 12 000600 0.100 BT1
134.000 .o analog 0 134.000 .p analog 1
from this header file i need to read the place ,time and other numbers and wants to insert in to my plots also
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
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)

Also look at just using the import tool to import them as a cell array:
Home Tab -> Import Data -> Select your file

Asked:

on 25 Sep 2014

Commented:

on 26 Sep 2014

Community Treasure Hunt

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

Start Hunting!