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

조회 수: 5 (최근 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 CenterFile Exchange에서 Text Files에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by