MATLAB: How to combine data in multiple excel files an write the combined data in a new excel file

importing excel data

I have in one folder a lot of excel files.Each of excel file contain data like this:(for example)
(First excel file)
1 2 3
1.1 2.2 3.3
80 90 91
(second excel file)
4 5 6
4.4 5.5 6.6
88 87 86
I want to combine only row 1 and row 2 to become like this in a newly created excel file.
1 2 3 4 5 6
1.1 2.2 3.3 4.4 5.5 6.6
Can someone help me to solve this problem.(Thank you)

Best Answer

Hi
a=xlsread('name1.xlsx');
b=xlsread('name2.xlsx');
N=[a(1:2,:) b(1:2,:)]
xlswrite('New.xlsx',N);
files with similar names (name1.xlsx,name2.xlsx,name3.xlsx,...):
b=[];
for i=1:n
name=['name' num2str(i) '.xlsx'];
a=xlsread(name);
b=[b a(1:2,:)];
end
xlswrite('New.xlsx',b);