Read tab deliminated txt file with two row header.

2 views (last 30 days)
This is tied to using R2012a.
I have a large tab deliminated text file (the current one I'm working on is ~[55,200 x 295], but others could be large/smaller), where the first row contains both string and text values, and the second row contains just text values (the remaining rows are numeric values). The format for the first five columns (which repeats over all 295 columns) over the two rows of the header are:
%s %s %e %s %d
%s %s %s %s %s
When I use importdata() and specify the header as being two rows, the numeric data comes in without an issue, but not the header data. Specifically, the second row of the header is fine, but the first row is mashed into one cell with the delimiter removed. I can't have this, as some of the values in the first of the header are important and need to be used.
Any suggestions?

Answers (1)

Star Strider
Star Strider on 20 Apr 2015
I would be tempted to read the first two rows with fscanf and the rest of the file with textscan.
I can’t be definitive because I don’t have a representative section of your text file to experiment with. (The first 5 rows, including the two-row header, would be enough.)

Categories

Find more on Characters and Strings 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!