read .xls file from multiple folder and export to result.xls

I have folders (z ii zjj) with ii=1:100 and jj=1:150 and each folder contains 1 file excel test.xls, test.xls is 1x360 data. I want to read test.xls and export to file result.xls. result.xls is 15000x360 data (100*150=15000), test.xls at z 0z 0 is at column 1, test.xls at z 0z 1 is at column 2..... test.xls at z 100z 150 is at column 15000.
for ii = 0 : 100
for jj=1:150
source_dir = sprintf('E:/zzzz/z %dz %d',ii,jj);
data = xlsread( fullfile(source_dir, 'test.xlsx') );
results(jj, :) = data; %%%%I think wrong in hear
end
end
xlswrite( 'E:/result.xlsx', results );

 Akzeptierte Antwort

results = zeros(500, 360);
for i = 1 : 500
source_dir = sprintf('D:\zzzz\z%d',i);
data = xlsread( fullfile(source_dir, 'test.xls') );
results(i, :) = data;
end
xlswrite( 'D:\result.xls', results );

6 Kommentare

it is not working.
Warning: Escaped character '\z' is not valid. See 'doc sprintf' for supported special characters.
Error using xlsread (line 132)
XLSREAD unable to open file 'E:\test.xls'.
File 'E:\test.xls' not found.
source_dir = sprintf('D:\\zzzz\\z%d',i);
viet le
viet le am 5 Sep. 2016
Bearbeitet: viet le am 5 Sep. 2016
I think. Thanks
source_dir = sprintf('D:/zzzz/z%d',i);
If I change z1, z2, z3, z4 to z 0z 1, z 0z 2, z 1z 1, z 1z 2. how to modify your code.
for ii = 0 : 1
for jj=1:2
source_dir = sprintf('E:/zzzz/z %dz %d',ii,jj);
data = xlsread( fullfile(source_dir, 'test.xlsx') );
results(1, :) = data;
end
end
xlswrite( 'E:/result.xlsx', results );
K = 0;
for ii = 0 : 1
for jj=1:2
source_dir = sprintf('E:/zzzz/z %dz %d',ii,jj);
data = xlsread( fullfile(source_dir, 'test.xlsx') );
K = K + 1;
results(K, :) = data;
end
end
xlswrite( 'E:/result.xlsx', results );
Thanks a lot

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by