Loop filename and variable name

2 ビュー (過去 30 日間)
Karl
Karl 2013 年 5 月 8 日
I want to make a loop that loops over the number 2011 in the following script.
[~, ~, raw] = xlsread('Q:\Karl\HH\FUT2013\LOTTE\2011.xlsx','B8:I18');
H2011 = reshape([raw{:}],size(raw));
[~, ~, raw] = xlsread('Q:\Karl\HH\FUT2013\LOTTE\2011.xlsx','B28:I38');
G2011 = reshape([raw{:}],size(raw));
As you can see, "2011" is the filename, but also used in the matrix definitions (H2011, G2011). Also, I call on a specific cell range from the excelfiles (B8:I18, b28:I38).
I have several excelfiles with names "2011", "2012", "2013_1", "2014_1", "2014_1s2" and "2014_1s5". Instead of repeating the excact same commands as aboove by changing "2011" in the filaname and matrix name for all the names mentioned, I wish to make a loop that does this. Does anybody have suggestions?
I have asked the same question before, http://www.mathworks.se/matlabcentral/answers/74778-loop-file-and-variablenames-when-importing, but the answer didn't work.

回答 (1 件)

Image Analyst
Image Analyst 2013 年 5 月 8 日
  1 件のコメント
Karl
Karl 2013 年 5 月 8 日
I think I get the loading part. The problem is looping over the variable definitions...How do change "H2011" and "G2011" in my example with H(i) and G(i) where i = 2011, 2012, 2013_1, 2014_1, 2014_1s2 and 2014_1s5?

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

カテゴリ

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