how to read multiple sheets (Tab) data and save it in a single matrix?

7 ビュー (過去 30 日間)
Hydro
Hydro 2018 年 5 月 19 日
コメント済み: Johann Martinez 2021 年 2 月 10 日
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

採用された回答

Majid Farzaneh
Majid Farzaneh 2018 年 5 月 19 日
Hi, I hope this can help you:
[~,SheetNames] = xlsfinfo('Yr00.xlsx');
nSheets = length(SheetNames);
Data=[];
for ii=1:nSheets
Name=SheetNames{ii};
Data=[Data, xlsread('Yr00.xlsx',Name)];
end
S.Data=Data
  13 件のコメント
Johann Martinez
Johann Martinez 2021 年 2 月 10 日
Hi all! It doesn't work thw accepted answer since Matlab 2019a presents lot of issues with xlsinfo(), and xlsread().
Does anyone could state another proposal with current well worked Matlab's functions ?
Thanks in advance.

サインインしてコメントする。

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2018 年 5 月 19 日
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 件のコメント
Hydro
Hydro 2018 年 5 月 19 日
Hello Walter,
Gave me the matrix dimension error. Tried to attach my excel sheet, but is not supported? I have many excel files like this- that's why looking for a code as doing it one by one would be very laborious.
Walter Roberson
Walter Roberson 2018 年 5 月 20 日
You can zip up .xls and .xlsx and attach those.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSpreadsheets についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by