MATLAB Answers

0

Create a table in MatLab with specific data in different spreadsheets in one Excel File.

Asked by Leon Wohlgemuth on 19 Oct 2019
Latest activity Commented on by Leon Wohlgemuth on 21 Oct 2019
Hello together,
I have an Excel File with 10 spreadsheets and I want to import data (always range: A2:K7) from every spreadsheet into a table in MatLab. I want to create a Loop so that the data is displayed beneath one another.
Thank you for your support!

  0 Comments

Sign in to comment.

1 Answer

Answer by Stephan
on 19 Oct 2019
Edited by Stephan
on 19 Oct 2019
 Accepted Answer

Use the sheet option from the readtable function to loop through the single sheets. Indexing the values correctly in the table you create will let the data appear the way you want. in the given link you also find how to select the range of the Excel document.

  5 Comments

filename = 'NASDAQ Company Data.xlsx';
sheets = sheetnames(filename);
xlRange = 'A1:K7';
data = cell(numel(sheets),1);
for k = 1:numel(sheets)
data{k} = readtable(filename,'Sheet',sheets(k),'Range',xlRange,...
'PreserveVariableNames',true);
end

Sign in to comment.