Azzera filtri
Azzera filtri

how to use xlsread for creating new matrices?

2 visualizzazioni (ultimi 30 giorni)
maryam
maryam il 21 Nov 2014
Commentato: maryam il 21 Nov 2014
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

Risposte (2)

Image Analyst
Image Analyst il 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.
  1 Commento
maryam
maryam il 21 Nov 2014
dear Image Analyst .unfortunately i couldn't understand what u mean. how i can run demo file?

Accedi per commentare.


Geoff Hayes
Geoff Hayes il 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!
  1 Commento
maryam
maryam il 21 Nov 2014
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.

Accedi per commentare.

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by