how to use xlsread for creating new matrices?
조회 수: 2 (최근 30일)
이전 댓글 표시
I have 1000 excel files (named H) and need to import the parameters of sheet 2 (named Q) to 1000 new matrices in matlab for analysis. i used this code in command window and got answer: Q1=xlsread('H(1)','Q'). but when i use the following code in m.file it doesn't work. could you help me to correct my code? thank you in advance
for i=1:1000
Q1(i)=xlsread('H(i)','Q');
end
댓글 수: 0
답변 (2개)
Image Analyst
2014년 11월 21일
Geoff told you how to prepare the filename and that's good.
If you don't want this to take forever, because it will have to launch Excel 1000 times and shutdown Excel 1000 times, you should use ActiveX instead of xlsread(). You launch Excel once, open all the workbooks, then shutdown Excel once. It will be a lot faster. I attach a demo where I do it on one or two workbooks.
Geoff Hayes
2014년 11월 21일
Maryam - please clarify what you mean by your 1000 files being named H. Are your files named H(1).xlsx, H(2).xlsx, etc.? If so, then you would build your file names using sprintf as
for k=1:1000
filename = sprintf('H(%d).xlsx',k);
end
If the matrices from each Q worksheet are of different dimensions, then you will want to use a cell array to store all of the data. Something like
Q = cell(1000,1);
for k=1:1000
filename = sprintf('H(%d).xlsx',k);
Q{k} = xlsread(filename,'Q');
end
Try the above and see what happens!
참고 항목
카테고리
Help Center 및 File Exchange에서 Spreadsheets에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!