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

2 ビュー (過去 30 日間)
Samantha Chong
Samantha Chong 2016 年 1 月 8 日
回答済み: Ingrid 2016 年 1 月 8 日
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!

回答 (1 件)

Ingrid
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

カテゴリ

Help Center および File ExchangeSpreadsheets についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by