フィルターのクリア

Read in excel sheets with a loop

46 ビュー (過去 30 日間)
Benjamin Cowen
Benjamin Cowen 2017 年 7 月 17 日
編集済み: Stephen23 2017 年 7 月 17 日
I have the following:
data1 = xlsread('C:\Users\Ben\example.xlsx','PKA1');
data2 = xlsread('C:\Users\Ben\example.xlsx','PKA2');
All the way up to 24.
How can I create a loop that reads in data1, data2, without writing them all out?
  1 件のコメント
Stephen23
Stephen23 2017 年 7 月 17 日
編集済み: Stephen23 2017 年 7 月 17 日
"How can I create a loop that reads in data1, data2, without writing them all out?"
Read this to know why that would make slow, buggy, complicated code:
Or read what the MATLAB documentation says about that idea: "A frequent use of the eval function is to create sets of variables such as A1, A2, ..., An, but this approach does not use the array processing power of MATLAB and is not recommended. The preferred method is to store related data in a single array"
And then use indexing, which is fast, simple, neat, easy to debug, easy to understand, etc, etc, and is exactly as recommended in the MATLAB documentation:

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

回答 (1 件)

John
John 2017 年 7 月 17 日
You can use the function xlsfinfo to obtain a list of all the sheets in your workbook "example.xlsx".
[~,sheets] = xlsfinfo('C:\Users\Ben\example.xlsx')
for i = 1:length(sheets)
data{i} = xlsread('C:\Users\Ben\example.xlsx',sheets{i}
end

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by