How to read multiple .csv and store all the data into one sheet

5 views (last 30 days)
Hi all,
I have 5 .csv files: 01.csv, 02.csv, 03.csv, 04.csv, 05.csv
with headers on the row 1-3, date&time on row 4:end column 1, water level data on row 4:end , column 2 and 3. Please see the image for one example of the .csv file. I managed to read the numeric data for each of the .csv file. Problems that I'm facing:
1. Store all the data from all .csv files into one big sheet
2. Reading the date&time and store into the same big sheet
Code that I'm currently using:
MEAS.INfolder='\\auper1-stor\Projects\43802036\Transfer_In\08012016_VRCA\csvFiles';
cd (MEAS.INfolder);
csvFiles=dir('*.csv');
numfiles=length(csvFiles);
for k=1:numfiles
csvFiles(k,1).tide=csvread(csvFiles(k,1).name,',',1);
end
k=k+1; %This code only allows me to read the data from each .csv files.
Thanks!

Answers (1)

Ingrid
Ingrid on 8 Jan 2016
I would recommend you to use textscan instead of csvread
for k=1:numfiles
fid = fopen(csvFiles(k,1).name);
filedata{k} = textscan(fid, '%f/%f/%f %f:%f:%f, %f, %f', 'Headerlines',3);
close(fid);
end
mergeddata = [filedata{:}];
than you can use datenum on the first six columns to get the date and time in the format that you want

Community Treasure Hunt

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

Start Hunting!