How to selectively import multiple sheets from an xls file

1 visualizzazione (ultimi 30 giorni)
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

Risposta accettata

Image Analyst
Image Analyst il 10 Ott 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 Commento
Debanjan
Debanjan il 10 Ott 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.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Language Fundamentals in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by