How to selectively import multiple sheets from an xls file

1 view (last 30 days)
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

Accepted Answer

Image Analyst
Image Analyst on 10 Oct 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 Comment
Debanjan
Debanjan on 10 Oct 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.

Sign in to comment.

More Answers (0)

Categories

Find more on Language Fundamentals in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!