questions about CSVREAD when import data into MATLAB

조회 수: 8 (최근 30일)
Xiaoran Song
Xiaoran Song 2014년 7월 12일
편집: Matthew Fricke 2015년 1월 22일
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,

답변 (2개)

dpb
dpb 2014년 7월 12일
편집: dpb 2014년 7월 12일
... 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.

Matthew Fricke
Matthew Fricke 2015년 1월 22일
편집: Matthew Fricke 2015년 1월 22일
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.

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by