Importing Data from Excel

1 回表示 (過去 30 日間)
Ali Movahed
Ali Movahed 2017 年 2 月 13 日
コメント済み: Ali Movahed 2017 年 2 月 15 日
Hi everyone, I have 32 Excel files and want to Combine the second column of all These files. I have written a code, but ist so disappointing. could you suggest me decent way? Thank you in advance!
m1=xlsread('1.xlsx','B2:B18183'); m2=xlsread('2.xlsx','B2:B18183'); m3=xlsread('3.xlsx','B2:B18183'); m4=xlsread('4.xlsx','B2:B18183'); m5=xlsread('5.xlsx','B2:B18183'); m6=xlsread('6.xlsx','B2:B18183'); m7=xlsread('7.xlsx','B2:B18183'); m8=xlsread('8.xlsx','B2:B18183'); m9=xlsread('9.xlsx','B2:B18183'); m10=xlsread('10.xlsx','B2:B18183'); m11=xlsread('11.xlsx','B2:B18183'); m12=xlsread('12.xlsx','B2:B18183'); m13=xlsread('13.xlsx','B2:B18183'); m14=xlsread('14.xlsx','B2:B18183'); m15=xlsread('15.xlsx','B2:B18183'); m16=xlsread('16.xlsx','B2:B18183'); m17=xlsread('17.xlsx','B2:B18183'); m18=xlsread('18.xlsx','B2:B18183'); m19=xlsread('19.xlsx','B2:B18183'); m20=xlsread('20.xlsx','B2:B18183'); m21=xlsread('21.xlsx','B2:B18183'); m22=xlsread('22.xlsx','B2:B18183'); m23=xlsread('23.xlsx','B2:B18183'); m24=xlsread('24.xlsx','B2:B18183'); m25=xlsread('25.xlsx','B2:B18183'); m26=xlsread('26.xlsx','B2:B18183'); m27=xlsread('27.xlsx','B2:B18183'); m28=xlsread('28.xlsx','B2:B18183'); m29=xlsread('29.xlsx','B2:B18183'); m30=xlsread('30.xlsx','B2:B18183'); m31=xlsread('31.xlsx','B2:B18183'); m32=xlsread('32.xlsx','B2:B18183'); recon=[ m1 m2 m3 m4 m5 m6 m7 m8 m9 m10 m11 m12 m13 m14 m15 m16 m17 m18 m19 m20 m21 m22 m23 m24 m25 m26 m27 m28 m29 m30 m31 m32];

採用された回答

dpb
dpb 2017 年 2 月 13 日
d=dir('*.xlsx'); % return directory list of all Excel files
x=[];
for i=1:length(d)
x=[x;xlsread(d(i).name,'B:B');
end
  3 件のコメント
dpb
dpb 2017 年 2 月 14 日
編集済み: dpb 2017 年 2 月 14 日
Then just remove the semicolon in the concatenation construct to do a horzcat instead of vertcat--
x=[x xlsread(d(i).name,'B:B');
Or, reshape the column vector above after the fact--
x=reshape(x,length(x)/length(d),[]).';
This will require that every spreadsheet indeed have identially the same number of elements or will fail spectacularly, though...while the other will succeed (albeit it gives up which set belongs to which original sheet if aren't same length) which is why did it that way originally.
Ali Movahed
Ali Movahed 2017 年 2 月 15 日
Thank you so much!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Import from MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by