How to selectively import multiple sheets from an xls file

1 Ansicht (letzte 30 Tage)
Debanjan
Debanjan am 10 Okt. 2014
Kommentiert: Debanjan am 10 Okt. 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

Akzeptierte Antwort

Image Analyst
Image Analyst am 10 Okt. 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 Kommentar
Debanjan
Debanjan am 10 Okt. 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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Language Fundamentals finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by