MATLAB: How to combine multiple files into one .csv

combinemultiple filesone

Hello everyone!
I would really appreciate your help on the following:
I have some .csv files with the exact same format (Attached you can find two of them) and I want to combine them to one single file . So far I have attempted the following lines of code but when I run them, I only get the contents of the first file, not both of them.
Is there anything I can do??
filenames={'C:\PhD\Projects\LIFE ASTI\C.3\WRF_main_TS_2015_ALL\WRF_Times_ALB+EMISS_FINAL2015\WRF_Thessaloniki_stations_2015\Tapp\Airport\Hourly_Stats Airport Tapp .csv','C:\PhD\Projects\LIFE ASTI\C.3\WRF_main_TS_2015_ALL\WRF_Times_ALB+EMISS_FINAL2015\WRF_Thessaloniki_stations_2015\Tapp\Eptapurgio\Hourly_Stats Eptapurgio Tapp .csv'};
filenames = filenames.';
[~,~,RAW1]=xlsread(filenames{1});
for i=1:size(filenames,1)
[num,~,~]=xlsread(filenames{i});
RAW1=[RAW1;num2cell(num)];
end
xlswrite('C:\PhD\Projects\LIFE ASTI\C.3\WRF_main_TS_2015_ALL\WRF_Times_ALB+EMISS_FINAL2015\WRF_Thessaloniki_stations_2015\Tapp\CombinedFile.csv',RAW1)

Best Answer

If I run your code and pause it after the first execution of the for loop, the num variable is empty, so something might be up with the file formats? At least, it explains why you only get the first file out, as you append empty arrays to your first file every loop.
I assume you want the header from the first file + the numeric data from the first and second files printed out? This does the trick, although I shudder at the file format ;) it should also work if your input is 100 files instead of 2.
filenames={'C:\PhD\Projects\LIFE ASTI\C.3\WRF_main_TS_2015_ALL\WRF_Times_ALB+EMISS_FINAL2015\WRF_Thessaloniki_stations_2015\Tapp\Airport\Hourly_Stats Airport Tapp .csv','C:\PhD\Projects\LIFE ASTI\C.3\WRF_main_TS_2015_ALL\WRF_Times_ALB+EMISS_FINAL2015\WRF_Thessaloniki_stations_2015\Tapp\Eptapurgio\Hourly_Stats Eptapurgio Tapp .csv'};
filenames = filenames.';
[~,~,RAW]=xlsread(filenames{1});
for i=1:size(filenames,1)
[~,~,all]=xlsread(filenames{i});
RAW{i+1}=all{2};
end
xlswrite('C:\PhD\Projects\LIFE ASTI\C.3\WRF_main_TS_2015_ALL\WRF_Times_ALB+EMISS_FINAL2015\WRF_Thessaloniki_stations_2015\Tapp\CombinedFile.csv',RAW)