CSV with multiple headers

Hi All,
Does anyone know how to open a csv which contains multiple headers and matrices? The problem is that the file alternates between headers and data.
I've tried 'importdata', but it is only effective at importing the first set of headers and subsequent data, while ignoring the rest.
Thanks so much for any and all help.
David Koweek
Here is an example of the file:
2012-07-19 04:30:06 UTC-7
-333abbcf:138811c920c:-6503
MEAS Cond.1
Time [s],Cond [mS/cm],dK/dt [(mS/cm)/min],Temperature [∞C]
0.0,51.51144790649414,-0.02382662519812584,24.276662826538086
2.0,51.56147766113281,1.7485476732254028,24.286495208740234
4.0,51.60802459716797,1.1739529371261597,24.29308319091797
6.0,51.65995788574219,1.4062501192092896,24.299636840820312
Initial mV reading.1
Time [s],Measured value [mV],dU/dt [mV/min],Temperature [∞C]
0.0,-64.26211547851562,0.0,25.05116081237793
2.0,-64.42849731445312,2.5588481426239014,25.020214080810547
4.0,-64.51497650146484,-2.3727076053619385,24.996685028076172
Initial pH reading.1
Time [s],Measured value,dU/dt [mV/min],Temperature [∞C]
0.0,7.968907356262207,0.0,24.967355728149414
2.0,7.968979835510254,-1.1694594621658325,24.947696685791016
4.0,7.968742847442627,1.0136315822601318,24.896135330200195
MET mV.1
Volume [mL],Measured value [mV],dMV [mV],Time [s],Temperature [∞C]
0.4999999701976776,93.01419067382812,0.0,0.0,25.01376724243164
0.5149999856948853,103.09514617919922,10.080955505371094,33.803192138671875,25.01731300354004
0.5299999713897705,118.78630065917969,15.691154479980469,62.501800537109375,25.014734268188477
0.5449999570846558,141.07925415039062,22.292953491210938,96.80340576171875,25.020214080810547
0.559999942779541,159.33139038085938,18.25213623046875,128.801513671875,25.01731300354004
0.574999988079071,171.2117919921875,11.880401611328125,156.80532836914062,25.017635345458984

 Accepted Answer

Walter Roberson
Walter Roberson on 31 Jul 2012

0 votes

You might be able to use textscan(), processing a piece at a time. If not, then you will have to use more basic I/O such as fgetl() and parse it yourself.
dlmread() and csvread() will be useless for this purpose.

2 Comments

Hi Walter,
Thanks for the advice. Could you explain a bit more about what you mean "processing a piece at a time"? How could I open the file more than once to separate out the segments of interest?
Thanks
Dave
With textscan() you only open the file once, and then you pass the file identifier into textscan().
If the portions you need to read are fixed size, then you can specify the number of lines (really the number of times to apply the given format) in the call to textscan().
If the portions are variable length, often there is trouble. There is a Technical Solution that shows an example of reading in varying length blocks; if I recall correctly, that example works by specifying a simple '%f' as the entire format, and that somehow magically that manages to detect and stop at empty lines. There is evidence that in at least some versions if you specify at more complex format such as '%f%f%f%f%f' to read five values per line, then it might not be able to detect and stop at empty lines.

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!