Import data with several sheets

Dear All,
I have a 2464x2464 matrix for 14 years saved in an excel file. Each working sheet represent one year including the same matrix, such that the data points change over time. I do not have specific time variables included, just the data. How i can import the whole matrix and make Matlab understand it such that i can use the matrix and calculate the development of the rows over time without creating 14 datasets?
Thanks in Advance

 Accepted Answer

hello Victoria
happy new year first !
this little piece of code will import evry sheet and stack the data , I assumed you want to have them stacked vertically
it assumes the number of columns are the same in every sheet
% Importing Data from excel across multiple sheets and filenames.
filename = 'file.xlsx';
[~,sheet_name]=xlsfinfo(filename)
data_all = [];
for k=1:numel(sheet_name)
[data,TXT,RAW]=xlsread(filename,sheet_name{k})
% stack data vertically
data_all = [data_all ; data];
end

4 Comments

Hello Mathieu,
Thanks for you anwser and Happy new year to you too :) .
I tried it a couple of times but it only sums up the different sheets into one matrix. Maybe my questions was confusing I am sorry, I wanted to create something like 2464x2464x14, such that i can select the year with the last column. Do you have any idea ?
greetings
hello Victoria
ok - I misunderstood the output format
this is the correct code for what you ask for :
% Importing Data from excel across multiple sheets and filenames.
filename = 'file.xlsx';
[~,sheet_name]=xlsfinfo(filename)
data_all = [];
for k=1:numel(sheet_name)
[data,TXT,RAW]=xlsread(filename,sheet_name{k});
% export to matlab 3D matrix
matrix(:,:,k) = data;
end
Thanks Mathieu,
it worked.
All the best for you. :)
You're welcome !!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!