How to read multiple .csv and store all the data into one sheet
2 次查看(过去 30 天)
显示 更早的评论
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!
0 个评论
回答(1 个)
Ingrid
2016-1-8
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
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spreadsheets 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!