how to use xlsread for creating new matrices?
1 view (last 30 days)
Show older comments
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 Comments
Answers (2)
Image Analyst
on 21 Nov 2014
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
on 21 Nov 2014
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!
See Also
Categories
Find more on Spreadsheets in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!