views:

167

answers:

1

Dear all,

Does anyone have some advise how to read a comma separated data file into matlab? The simple solutions (like dlmread, fscanf) do not seem to work, as there are multiple (10) lines of header information. The closest I got to a solution is:

C=textscan(datafile)
G=cell2mat(C{1,1}(34:endoffile)}) //34 is the line the data starts
V=str2num(G)

the problem here is that the data for instance looks like this:

;1.0345,937,18,763
;1.0355,947,4,652
etc.

When converting into the matrix all strings in the cell have to be of the same size, otherwise an error using 'vertcat' is given. If no other option, I could just delete the header in lets say notepad, but with many many files this would be a tedious job. Thanks in advance!

Matthijs

+5  A: 

DLMREAD accepts starting row/column parameters, or alternatively a range parameter. So if your data starts on line 10, you could try

V = dlmread(datafile, '', 9, 0);

If you prefer TEXTSCAN, you can specify a number of HeaderLines to skip:

V = textscan(datafile, ..., 'HeaderLines', 10, ...);

Scan down to "User Configurable Options" on the documentation page for more details.

mtrw
dlmread is the way to go
Geoff