MATLAB Answers

Xiaoran Song

questions about CSVREAD when import data into MATLAB

Asked by Xiaoran Song
on 12 Jul 2014
Latest activity Edited by Matthew Fricke
on 22 Jan 2015

I am now using CSVREAD to import csv datas ,some of the datas are as follows The first line of CSV is head line and my matlab scrip is

m11=csvread('SPC.csv',2,0);
However sometimes, MATLAB terminate with errors saying "
Error using dlmread (line 139)
Empty format string is not supported at the end of a
file.

Error in csvread (line 48) m=dlmread(filename, ',', r, c);

Error in MAIN_WB_DYNA_ANASIS (line 68) af=csvread('DISNODE.csv',2,0);

time,114059,
0,0,
0.00096509,-6.4337e-011,
0.00193018,-8.5843e-010,
0.0029757,-4.1747e-009,
0.00394079,-1.1399e-008,
0.0049863,-2.5976e-008,
0.00595139,-4.7814e-008,
0.0069969,-8.3311e-008,
0.00796199,-1.2971e-007,
0.00892709,-1.9175e-007,
0.0099726,-2.7931e-007,
0.0109377,-3.8154e-007,
0.0119832,-5.1866e-007,
0.0129483,-6.7264e-007,

  1 Comment

Image Analyst
on 12 Jul 2014

You forgot to attach the csv file.

Tags

Products

No products are associated with this question.

2 Answers

Answer by dpb
on 12 Jul 2014
Edited by dpb
on 12 Jul 2014

... The first line of CSV is head line ...

Per the help file for csvread,

M = csvread('FILENAME') reads a comma separated value formatted file
  FILENAME.  The result is returned in M.  The file can only contain
  numeric values.

Note the last sentence above--if there's a header line, you can't use csvread (or dlmread, either, as you can observe from the error message that the former is just a wrapper around the latter.

Use importdata or textscan or even textread instead...

importdata will automagically try to determine the number of header line(s); use the 'headerline' named argument in the textXXX routines.

  0 Comments


Answer by Matthew Fricke
on 22 Jan 2015
Edited by Matthew Fricke
on 22 Jan 2015

You probably have a blank line at the end of your input file or your input file uses a newline character from a different operating system such as OS X or Windows. The way you skip the headers by beginning the read on line 2 should work fine.

  0 Comments


Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply today