how to use xlsread for creating new matrices?

조회 수: 2 (최근 30일)
maryam
maryam 2014년 11월 21일
댓글: maryam 2014년 11월 21일
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

답변 (2개)

Image Analyst
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.
  댓글 수: 1
maryam
maryam 2014년 11월 21일
dear Image Analyst .unfortunately i couldn't understand what u mean. how i can run demo file?

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


Geoff Hayes
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!
  댓글 수: 1
maryam
maryam 2014년 11월 21일
thank you for your answer. yes, my files are named H(1)...H(1000) and in sheet 2 of them there is a 10*10 matrix named Q. now i want to create 1000 new 10*10 matrix in matlab. i attach two xls files to see what i mean. thank you for giving your time to me.

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

카테고리

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