Error while extracting data..... trying to parse data in order to make a big data set..

조회 수: 1 (최근 30일)
Hi i am trying to read data of multiple csv files that contains numeric,text data which is delimited by commas...
format of the raw data in these csv.files is shown below.
16744C9796,96440457110,08/11/11,10:50:40,08/11/11,11:19:32,28.867,1
136CC15E35,83428990517,08/11/11,11:05:37,08/11/11,11:32:00,26.383,1
F40B93397476,268330551833718,08/11/11,11:05:48,08/11/11,11:32:03,26.250,1
21FEAF3F48,146006818632,08/11/11,11:08:53,08/11/11,11:33:53,25.000,1
405FBEF422BE,70779969741502,08/11/11,11:10:15,08/11/11,11:13:48, 3.550,0
A0960EACF9,689712311545,08/11/11,11:10:42,08/11/11,11:14:01, 3.308,0
1474118A3811,22488743032849,08/11/11,11:11:07,08/11/11,11:13:55, 2.800,0
I tried to use the following code but i am getting this error.
d = dir('*.csv');
N_File = numel(d);
C = {};
for num = 1:N_File
k = fullfile(d(num).name);
dat = myfileread(d(num).name,num);
C = [C;dat];
num=num+1;
end
??? Error using ==> datenum at 182
DATENUM failed.
Error in ==> myfileread at 8
t1 = datenum(strrep(strcat(data{3},'-',data{4}),'-',' '));
Caused by:
Error using ==> datevec at 286
Cannot parse date .
*
------------ The code for the above function myfileread is-----------*
function outdata = myfileread(fname,k)
% read from file
fid = fopen(fname);
data = textscan(fid,'%s%f%s%s%s%s%f%f','delimiter',',');
fclose(fid);
% extract time stamps and convert to serial date numbers
t1 = datenum(strrep(strcat(data{3},'-',data{4}),'-',' '));
t2 = datenum(strrep(strcat(data{5},'-',data{6}),'-',' '));
% combine together into one big cell array
outdata = num2cell(k*ones(size(data{1}))),data{1},num2cell([data{2},t1,t2,data{7},data{8}])];
Thanks in advance.

채택된 답변

Fangjun Jiang
Fangjun Jiang 2011년 12월 15일
Check for a problematic .csv file. If using the .csv file you shown, it works fine.
  댓글 수: 3

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by