Putting the content of an array cell into an xlsread command.

I am trying to create a 'for loop' to cycle through all of the worksheets in an excel workbook. I created a column array with the exact names of all of the worksheets.
Here is my attempt to do this:
worksheets = {'Aaa'; 'Bbbbbbbbbb'; 'Ccccccc'...etc}
for i=1:10
WSName = worksheets(i,1)
Matrix = xlsread('C:\documents\workbook', sprintf('%s', WSName))
end
Can anyone tell me how to fix this to make it work? Is it possible?

 채택된 답변

Oleg Komarov
Oleg Komarov 2011년 2월 14일
Two things, once you created a cellstring with the wks names, you don't need to recreate it inside the loop and always specify the file extension:
worksheets = {'Aaa'; 'Bbbbbbbbbb'; 'Ccccccc'};
for i=1:10
Matrix = xlsread('C:\documents\workbook.xls',worksheets{i});
end
Oleg

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by