How do I change variable in a for loop?

3 ビュー (過去 30 日間)
Larissa Perez
Larissa Perez 2016 年 10 月 7 日
コメント済み: Star Strider 2016 年 10 月 7 日
Hi! I am new to Matlab, so struggling a bit.
I'd like to know how can I change the variable in a for loop, for each time it runs. That's what I am doing:
measurementnames = {'measurement1','measurement2','measurement3','measurement4','measurement5','measurement6','measurement7','measurement8','measurement9','measurement10','measurement11'};
for i = 1:numel(measurementnames) measureloop = measurementnames{i} ;
plot(measureloop(:,2),measureloop(:,11)) set(gca,'YDir','reverse') hold on
end
I have done something similar before and it worked, so I don't really know what's wrong now. Thank you so much!

採用された回答

Star Strider
Star Strider 2016 年 10 月 7 日
Using the eval function is generally not considered good programming practice (it can usually be avoided) but sometimes it may be necessary. I can’t run your code, so you’ll have to see if this works:
measureloop = eval(measurementnames{i});
  2 件のコメント
Larissa Perez
Larissa Perez 2016 年 10 月 7 日
thank you so much! it worked!
Star Strider
Star Strider 2016 年 10 月 7 日
My pleasure!

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

その他の回答 (0 件)

カテゴリ

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