How to selectively import multiple sheets from an xls file

1 次查看(过去 30 天)
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

采纳的回答

Image Analyst
Image Analyst 2014-10-10
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 个评论
Debanjan
Debanjan 2014-10-10
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Language Fundamentals 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by