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

3 views (last 30 days)
karan on 15 Dec 2011
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.
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];
??? 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',',');
% 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.

Accepted Answer

Fangjun Jiang
Fangjun Jiang on 15 Dec 2011
Check for a problematic .csv file. If using the .csv file you shown, it works fine.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!