reading multiple excel files

HI
I have multiple excel files at different folders. Lets say 5 excel files at 5 different folders. D:\1\1.xlsx.... to D:\10\10.xlsx!
I want to read the column of each excel sheet and store it to five variables in matlab. I am trying this, but i cant say like this..['dataname' num2str(k)] any help?
range='E1:E2500';
for k=1:5
fname=['d:\1' '\ALL000' num2str(k) '\F000' num2str(k) 'CH3.CSV'];
sheet=['F000' num2str(k) 'CH3'];
['dataname' num2str(k)]=xlsread(fname,sheet,range);
end
Thanks
Matt

5 comentarios

dpb
dpb el 11 de Jul. de 2014
Format code to be legible. If you can't read it clearly in preview window when asking, neither can we and the posting isn't yet ready for prime time.
Joseph Cheng
Joseph Cheng el 11 de Jul. de 2014
Editada: Joseph Cheng el 11 de Jul. de 2014
also why is dataname a string since that is not how the output works? why designate different variables why not a multi-column array or cell array? such that dataname(k) = {xlsread(fname......)}.
Matt
Matt el 11 de Jul. de 2014
ok, I make the code readable now.
I want to save the columins in matelabe like dataname1, dataname2,dataname3......... that is why i am using ['dataname' num2str(k)]!
Joseph Cheng
Joseph Cheng el 11 de Jul. de 2014
so.... then just pull it out of the multi-column array after the for loop. or use eval() but that has its own issues of why you shouldn't do it. see dpb's FAQ about why this isn't doing anything for you.
dpb
dpb el 11 de Jul. de 2014
Editada: dpb el 11 de Jul. de 2014
...I want to save ...like dataname1, dataname2,dataname3...
AGAIN, do NOT do this!!! (This way "there be dragons")
Use a name structure array or just ordinary arrays and reference the various data with the column number instead of "poofing" variables into the workplace.
While it is possible, it just leads to a nightmare later on to do so. There are languages (like REXX) that make such name creation a feature of the language, but Matlab is not one of those.

Iniciar sesión para comentar.

Respuestas (2)

dpb
dpb el 11 de Jul. de 2014

0 votos

D:\1\1.xlsx.... to D:\10\10.xlsx
...I want to read the column of each excel sheet and store it to five variables
Do NOT do this. See the FAQ for why not and the alternatives.

1 comentario

Joseph Cheng
Joseph Cheng el 11 de Jul. de 2014
thanks dpb i keep losing this link for the questions that ask to create incremental named variables.

Iniciar sesión para comentar.

Image Analyst
Image Analyst el 11 de Jul. de 2014

0 votos

If you have more than one workbook, you should really use ActiveX programming rather than xlsread(). It will be a lot faster. See attached demo. Store each set of data you read in to a column of an array. Let me know if you can't figure out how to adapt the demo to do that.

Etiquetas

Preguntada:

el 11 de Jul. de 2014

Respondida:

el 11 de Jul. de 2014

Community Treasure Hunt

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

Start Hunting!

Translated by