-1

My data in csv file looks like this:

2015/01/01;00:15;62;646;96;321;42;74;529;0;0
2015/01/01;00:30;245;74;854;62;154;93;354;0;0
......

the data is separated by semicolon and the first two columns are time, the rest are numerical data sampled.

I only want to import numerical data into matlab, I tried to use csvread:

M = csvread('data.csv',0,2,[0 2 500 10] );

But got error like this:

Error using dlmread (line 138) Mismatch between file and format string.

How should I fix this problem?

also tried textscan but failed..

6
  • Seriously? This is the 3rd question today that has been asked about this topic!
    – IKavanagh
    Nov 5, 2015 at 13:55
  • Everyone knows about SO now. The whole class gets an assignment, the whole class posts it on SO. Also, the data is not as the OP claims... Nov 5, 2015 at 15:04
  • Check if the , are separators or decimal delimiters (instead of the . which I expect Matlab to assume).
    – Schorsch
    Nov 5, 2015 at 15:39
  • some numerical data are separate in two cells next to each other, and judging by the error "Trouble reading 'Numeric' field from file (row number 1, field number 4) ==> ,51;622,8;1,5;208,8;246,83;179,54;268,04;0;0,;,,\n " matlab use ", " to express that , but why there is a \n at the end?
    – 杨子江
    Nov 5, 2015 at 16:02
  • 1
    It's not an assignment sure, but it'd help if you actually took some effort and searched to see if any questions you have have been asked in the past. This way you don't clutter this website and you don't waste our time.
    – rayryeng
    Nov 5, 2015 at 16:32

1 Answer 1

0

Use dlmread instead. It allows you to specify a custom delimiter, which csvread does not:

M = dlmread('data.csv', ';', 0, 2)

The first two elements should not be parsed, so their non-numerical nature should be correctly ignored.

2
  • still got error like this: Error using dlmread (line 138) Mismatch between file and format string. Trouble reading 'Numeric' field from file (row number 1, field number 4) ==> ,51;622,8;1,5;208,8;246,83;179,54;268,04;0;0,;,,\n Error in data(line 1) M = dlmread('data.csv',';',0,2 ); Is this problem related to the format of the data?
    – 杨子江
    Nov 5, 2015 at 14:56
  • Yes. From the error output, it is clear that the separators are both ';' and ',' in your actual data, not just ';' as you claim. In that case use textscan(), which is much kludgier. Nov 5, 2015 at 15:02

Not the answer you're looking for? Browse other questions tagged or ask your own question.