how to read multiple sheets (Tab) data and save it in a single matrix?
Mostra commenti meno recenti
Hello, I am trying to read an excel file with 19 sheets (tabs) whereas each tab has 365(or 366)*1 data. I want all the tabs to be on one sheet (all columns side by side) in a matrix form. I tried with code below but no success. Appreciate all the good thoughts and help.
[~,SheetNames] = xlsfinfo('Yr00.xlsx');
nSheets = length(SheetNames);
for ii=1:nSheets
Name=SheetNames{ii};
Data=xlsread('Yr00.xlsx',Name);
S(ii).Data=Data;
end
Risposta accettata
Più risposte (1)
Walter Roberson
il 19 Mag 2018
0 voti
That looks okay as far as it goes. What is left after that is putting the data all together in one matrix. For that purpose, how do you want to handle the leap year? Do you want the rows matched by calendar date, in which case 3/4 of the rows would have missing data for February 29? Or do you want the rows matched by day number of the year, in which case 1/4 of the rows would have one extra column? What "fill" value do you want to use for the "holes" ?
4 Commenti
Hydro
il 19 Mag 2018
Walter Roberson
il 19 Mag 2018
allvalues = [];
for ii = 1 : length(SS)
thisdata = SS(ii).Data;
if length(thisdata) == 366
allvalues = [allvalues, thisdata];
else
allvalues = [allvalues, [thisdata(1:59); nan; thisdata(60:end)]];
end
end
Sometimes it just isn't worth using fancy vectorized algorithms.
Hydro
il 19 Mag 2018
Walter Roberson
il 20 Mag 2018
You can zip up .xls and .xlsx and attach those.
Categorie
Scopri di più su Calendar in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!