Identify column headers in a text file
Show older comments
Dear all,
I am reading data from a text file with the standard format:
FILE TITLE
Header-1 Header-2 Header-3 Header-4 Header-5
58.1 Inf 7.0000 0 0
59.1 Inf 7.0000 0 0
60.1 7.7090e+04 4.8870 1.297e-05 129.7
61.1 Inf 7.0000 0 0
In each file, there is one line for a file title, followed by a series of numerical data columns with a mixture of numerical formats (engineering, integer, inf etc.). Each data column has its own text header. The number of data columns is variable.
I would like to obtain each column header, preferably as a cell of strings, and then use strcmp() to confirm the identity of each column.
I have tried various methods such as textscan and fgetl. The closest I can get is a character array, but this does not distinguish individual column names:
fid = fopen('file.txt', 'r');
firstline = fgetl(fid);
secondline = fgetl(fid);
>> whos secondline
Name Size Bytes Class Attributes
l 1x104 208 char
Thanks in advance for the help!
Best regards,
Louis
Accepted Answer
More Answers (0)
Categories
Find more on Text Files 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!