필터 지우기
필터 지우기

loading multiple excel files in a loop

조회 수: 1 (최근 30일)
Brian
Brian 2011년 7월 15일
댓글: Himmat 2015년 9월 18일
I have thousands of excel files that contain data in a 1440x~35 array. I only need a few columns in each file. The excel files are logically ordered with the pattern 1018ahua.xls, 1019ahua.xls, etc. I have tried loading columns in a loop using the xlsread command in a variety of ways and am always unable to do it. I use Matlab R2010b. Can anyone help me?

채택된 답변

Friedrich
Friedrich 2011년 7월 15일
Hi,
first of all doing a xlsread in a loop is a bad idea since you always open and close the EXCEL COM Server. You have to do it manually in a better way, like:
%open Excel
ex = actxserver('excel.application');
for i=1:thousands_of_excel_files
ex.Workbooks.Open('C:\absolut_path_to file\filename.xls')
out = get(ex.Range('B3:D6'),'Value')
end
ex.Quit
So if its really ordered like 1018ahua.xls, 1019ahua.xls and so on you can do
%open Excel
ex = actxserver('excel.application');
for i=1018:thousands_of_excel_files
ex.Workbooks.Open(['C:\absolut_path_to file\',num2str(i),'ahua.xls'])
out = get(ex.Range('B3:D6'),'Value')
end
ex.Quit
  댓글 수: 4
Image Analyst
Image Analyst 2014년 8월 20일
Katerina, start your own thread and attach your code (m-file) and full description of what "does not work" means to you (screenshots, error messages, etc.)
Himmat
Himmat 2015년 9월 18일
Hello Fredrich, I tried to use this code and facing a problem that output data is only from last excel sheet. I want to import column 1 and 3 from each excel file from a group of 10 and put it in one matrix. Can you suggest a way to do it. Thank you for your help.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Sean de Wolski
Sean de Wolski 2011년 7월 15일
Have you read: FAQ4.12?

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by