How can I get dynamic naming variables? So in a loop i need variables with names A1,A2,A3...... logic?

1 回表示 (過去 30 日間)
ck
ck 2016 年 5 月 1 日
編集済み: Stephen23 2019 年 6 月 19 日
the loop running should produce N outputs with each having label A1,A2,A3....An

回答 (1 件)

CS Researcher
CS Researcher 2016 年 5 月 1 日
You can use eval. Try this:
for i = 1:10
eval(['A' num2str(i) ' = i;']);
end
  2 件のコメント
ck
ck 2016 年 5 月 1 日
so I have An = strcat(1,2,3..) and n in the loop where It should go as A1,A2.....
can I use eval for that?
Stephen23
Stephen23 2016 年 5 月 1 日
編集済み: Stephen23 2019 年 6 月 19 日
Note that this forces you into writing slow, buggy, obfuscated code, that removes all of MATLAB code checking abilities and makes code difficult to debug.

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by