Can I import many different xls files at once?
2 ビュー (過去 30 日間)
古いコメントを表示
Example:
I want to write an m file for the following.
I want to import 20 different xls files, all located in one folder.
I want to find the sum of the values present in each xls file and produce the resultant sum of each xls file.
But I want all the xls files to be imported at once. I can't keep on importing one by one. Because in some cases the number of files may even increase to 50.
Someone could help me?
0 件のコメント
採用された回答
Azzi Abdelmalek
2013 年 1 月 19 日
編集済み: Azzi Abdelmalek
2013 年 1 月 19 日
d=struct2cell(dir('yourfolder/*.xls'))
file=d(1,:)
for k=1:numel(file)
res{k}=xlseread(file{k});
r_mean{k}=mean(res{k});
r_sum{k}=sum(sum(res{k}))
end
1 件のコメント
その他の回答 (1 件)
Image Analyst
2013 年 1 月 19 日
編集済み: Image Analyst
2013 年 1 月 19 日
You can't import them all "at once" - you have to do it one file at a time. The closest you could get to doing them "at once" is if you have the Parallel computing toolbox, and set up several processes to read in files in parallel.
But assuming you want to do them "at once" just to speed up the process, don't use xlsread() unless you want to wait forever because it will have to launch Excel and shutdown Excel every single time. You should use ActiveX. Search the forum for "actxserver" - many people, including me, have posted sample code. Or search the Mathworks site. This method, while more difficult to code, will be A LOT faster.
I presume you know how to use the sum() function to sum values. See Azzi's code if you don't.
You might be interested in this video tutorial: http://blogs.mathworks.com/videos/2012/03/28/matlab-tutorial-processing-an-excel-file-in-matlab/
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で ActiveX についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!