How to selectively import multiple sheets from an xls file

1 visualización (últimos 30 días)
Debanjan
Debanjan el 10 de Oct. de 2014
Comentada: Debanjan el 10 de Oct. de 2014
Hi,
I have an .xls file with over 50 sheets. i would like to import multiple sheets from the file.
Assuming an xls file named testfile.xls,, with sheets named Sheet 1, 2 ....50, what I would like to import is
n = [4,5,8,15,23,44];
for i = 1:length(n)
[M, strings, raw] = xlsread('testfile.xls','Sheet {n(i)}')
end
I tried using
[M, strings, raw] = xlsread('testfile.xls','Sheet %d',n(i))
and
[M, strings, raw] = xlsread('testfile.xls','Sheet 'num2str(nb(i)))
I am not sure how I should do this.
I would be most grateful for any help.
Thanks,
Regards, Deb

Respuesta aceptada

Image Analyst
Image Analyst el 10 de Oct. de 2014
Try
n = [4,5,8,15,23,44];
for k = 1:length(n)
sheetName = sprintf('Sheet %d', n(k));
[M, strings, raw] = xlsread('testfile.xls', sheetName);
end
Of course you're overwriting M on each iteration......
  1 comentario
Debanjan
Debanjan el 10 de Oct. de 2014
Thank you very much.. its working perfectly now.
Yeah I will be storing the values I need in a variable and clearing M after each iteration.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Language Fundamentals en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by