How to read all sheets from an excel and output them
조회 수: 187 (최근 30일)
이전 댓글 표시
I have an excel file that contains multiple sheets, each of them is 44*16. I used the following code to read the multiple sheets:
[~,sheet_name]=xlsfinfo('filename.xlsx');
for k=1:numel(sheet_name)
data{k}=xlsread('filename.xlsx',sheet_name{k});
end;
This code gives me sheet_name=1*8 cell, this includes the names of my sheets in this excel file, each of them looks shows as {44*16 double}. Then I want to read all the data from each sheet and plot them into one figure. I would like to know how should I read the data in from {sheet_name}. And I want to plot the figure using the "for" loop.
Thanks for helping.
댓글 수: 0
답변 (2개)
Fangjun Jiang
2018년 1월 30일
편집: Fangjun Jiang
2018년 1월 30일
Your code above already reads the data from all the sheets, i.e. data{1} contains the data from the first sheet, ..., data{8} contains the data from the 8th sheet.
To plot the data, add "figure;hold on" prior to your for-loop and then use plot() inside your for-loop. Reference the data as data{k}(row_index, col_index).
댓글 수: 0
Sulaymon Eshkabilov
2023년 2월 2일
편집: Sulaymon Eshkabilov
2023년 2월 2일
An alternative solution to this exercise with MATLAB recommended functions is:
clf
FName ='Exercise1.xlsx';
S_names = sheetnames(FName); % Recommended fcn: sheetnames()
for ii=1:numel(S_names)
D{ii}=readtable(FName, 'Sheet', S_names(ii)); % Recommended fcn: readtable() or readmatrix() or readcell()
plot(D{ii}.Var1, D{ii}.Var2), hold all
end
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Spreadsheets에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!