MATLAB Answers

How to use for loop with xlsread to read multiple sheets in an excel file

22 views (last 30 days)
mht6
mht6 on 6 Mar 2020
Answered: Sindar on 6 Mar 2020
I am trying to read the same cells of data from different sheets in a single excel file.
I would prefer to use xlsread if possible. Additionally, the sheets are named not numbered.
Thank you

  0 Comments

Sign in to comment.

Answers (1)

Sindar
Sindar on 6 Mar 2020
from the documentation:
num = xlsread(filename,sheet,xlRange) %reads from the specified worksheet and range.
so, just loop over the sheets (with sheetnames):
xlRange = 'B2:C3';
sheets = sheetnames(filename);
for ind=1:length(sheets)
num(ind) = xlsread(filename,sheets(ind),xlRange)
end

  0 Comments

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!