I have a bunch of csv files in a folder in following format, I want to extract complete time series from each (the numeric part from line #17), identify duplicate record and merge them in a ascending order according to year and date. Specific csv file is accessible via google drive link below
wnsnum 1
paroms Waterhoogte
loccod HOEKVHLD
locoms Hoek van Holland
rks_begdat 1993 07 09
rks_begtyd 00:00
rks_enddat 2014 31 12
rks_endtyd 23:50
begdat begtyd enddat endtyd rkssta
1993 07 09 00:00 2007 31 12 23:50 D
2008 01 01 00:00 2009 30 12 23:50 G
2009 31 12 00:00 2009 31 12 23:50 O
2010 01 01 00:00 2011 17 06 18:40 G
2011 17 06 18:50 2011 18 06 18:50 O
2011 18 06 19:00 2014 31 12 23:50 G
datum tijd bpgcod waarde kwlcod
1993 07 09 00:00 -70 0
1993 07 09 00:10 -69 0
1993 07 09 00:20 -68 0
1993 07 09 00:30 -67 0
1993 07 09 00:40 -68 0
1993 07 09 00:50 -70 0
1993 07 09 01:00 -69 0
1993 07 09 01:10 -69 0
1993 07 09 01:20 -68 0
1993 07 09 01:30 -67 0
1993 07 09 01:40 -65 0
1993 07 09 01:50 -64 0
1993 07 09 02:00 -62 0
1993 07 09 02:10 -61 0
1993 07 09 02:20 -61 0
1993 07 09 02:30 -59 0
1993 07 09 02:40 -58 0
1993 07 09 02:50 -55 0
Now my code is working in a following way:
SL_files = dir(sprintf('%s%s%s',fullfile(dirName),'\','*.csv'));
for idx = 1:size(SL_files,1)
disp(SL_files(idx,1).name)
fid = fopen(sprintf('%s%s%s',fullfile(dirName),'\',SL_files(idx,1).name));
data = textscan(fid, '%s %f %f %f %f %f %f', ...
'Delimiter',',', 'MultipleDelimsAsOne',1,'headerlines',16);
fclose(fid);
end
Now I could read the file. Now my problem is how to combine multiple files' data into one matrix and arrange them in a ascending order according to year and day values. Thanks!
I finally solve my problem. Here is the code:
numMat_All = [];
for idx = 1:size(SL_files,1)
disp(SL_files(idx,1).name)
fid = fopen(sprintf('%s%s%s',fullfile(dirName),'\',SL_files(idx,1).name));
data = textscan(fid, '%s %f %f %f %f %f %f', ...
'Delimiter',',', 'MultipleDelimsAsOne',1,'headerlines',16);
fclose(fid);
CharCell = data{1,1};
result = regexprep(CharCell,'[\s;:]+',' ');
numMat = cell2mat(cellfun(@str2num, result(:,1:end), 'UniformOutput', false));
numMat_All = [numMat_All;numMat];
data = []; CharCell = []; result = []; numMat = [];
end
dt = datetime([numMat_All(:,1:5), repmat(0,length(numMat_All),1)]);
T = table(dt,numMat_All(:,[6:7]));
T1 = sortrows(T,'dt');
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.