how to code variable to code
古いコメントを表示
like in box name have s1 s2 s3 s4 s5 s6 .. sn
s1 = 1
s2 = 2
s3 = 3
sn = n
**************************
for i=1:n
s<i> do something
end
************
behind s<> how to code variable to code
回答 (1 件)
madhan ravi
2019 年 7 月 3 日
0 投票
Completely terrible idea see https://in.mathworks.com/matlabcentral/answers/304528-tutorial-why-variables-should-not-be-named-dynamically-eval
8 件のコメント
Anantachai Chotkamsri
2019 年 7 月 3 日
編集済み: Anantachai Chotkamsri
2019 年 7 月 3 日
Walter Roberson
2019 年 7 月 3 日
The answer is "Don't DO That!"
There are ways to do it, but there are very very few good reasons to do it considering the alternatives.
Anantachai Chotkamsri
2019 年 7 月 3 日
編集済み: Anantachai Chotkamsri
2019 年 7 月 3 日
Rik
2019 年 7 月 3 日
Explain what you want to do. Then we can help you solve your actual problem.
Anantachai Chotkamsri
2019 年 7 月 3 日
Dennis
2019 年 7 月 3 日
I think you already identified the problem, do not create variables s1,s2,s3 i n the first place.
s=ones(1000,1);
for i=1:1000
s(i)=i+1;
end
Stephen23
2019 年 7 月 3 日
Indexing is simple, neat, and very effiicient (unlike what you are trying to do).
Indexing is also explained in the introductory tutorials:
and also explained in the link that madhan ravi gave you.
Anantachai Chotkamsri
2019 年 7 月 3 日
カテゴリ
ヘルプ センター および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!