Import multiple excel sheets with multiple columns each into variables

8 ビュー (過去 30 日間)
Shana VdS
Shana VdS 2018 年 5 月 30 日
編集済み: Stephen23 2018 年 5 月 31 日
Hey, I would like to import data from excel with multiple sheets. Every sheets has 2 columns and I would like to create a variable of every column in every sheet. How can I do this in Matlab?

採用された回答

Rishabh Rathore
Rishabh Rathore 2018 年 5 月 31 日
You can use xlsread(xls_file,sheet_no) to read from particular sheet, refer documentation. It will return data in matrix form. Once you have that, use array indexing to extract individual columns ,Matrix(:,col) gives column 'col' of 'Matrix'.
Using xlsread, loop through all the sheets to get data from individual sheets.
  2 件のコメント
Shana VdS
Shana VdS 2018 年 5 月 31 日
how can I create this loop and give every variable a name combined with the name of the sheet? For example time_sheet1
Stephen23
Stephen23 2018 年 5 月 31 日
編集済み: Stephen23 2018 年 5 月 31 日
"how can I create this loop and give every variable a name combined with the name of the sheet?"
Don't do that, unless you want to force yourself into writing slow, complex, buggy code that is hard to debug. Read this to know why dynamically accessing variable names is a bad way to write code:
Use indexing. Indexing is simple, neat, and very efficient. Indexing is what you should use. Store the sheet names and sheet data in cell arrays, and access them trivially using indexing.

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

その他の回答 (0 件)

カテゴリ

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