How do I import data from multiple pages in an xls-file to an x*y*z-matrix?

1 view (last 30 days)
Hi,
I am working with time-series data in a multi-page spreadsheet and would like to import it. Each pages have 17 variables over the time-span of 70 years and there are 25 pages. I can use [num, txt, raw] = xlsread('file.xls','pagename') to access the table in one individual page, but i would like to import it as a tensor if possible, to store it in a [X,Y,Z]-format, like as if the all the tables are "stacked on top of each other".
Would be neat if all the data for page 3 could be accessed simply by [:,:,3], or a specific value by on that page by, for example, [7,2,3].
My first instinct was to make a loop, but since the arguments in xlsread are strings I don't know how to do it. Is there a proper way?

Answers (1)

Cris LaPierre
Cris LaPierre on 2 Aug 2020
If the variables are the same in each sheet, readtable can be used to create a table datatype. You can then append the table from each sheet together. MATLAB will automatically align the tables by variable name. Maybe something like this (untested)?
[status, sheetNames] = xlsfinfo('file.xls');
% read in the first sheet
data = readtable(fullFileName, 'Sheet', 1)
% Read data from the remaining sheets
for s=2:length(sheetNames)
temp = readtable(fullFileName, 'Sheet', s);
% append to the table
data = [data;temp];
end

Categories

Find more on Cell Arrays in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!