Info
この質問は閉じられています。 編集または回答するには再度開いてください。
changing the name of a variable
1 回表示 (過去 30 日間)
古いコメントを表示
Hi,
I know that what I am asking for is not recommended but I need it. I have a loop and i want to change the name of the variable according to the loop:
for i=1:40 variable L I want it to be named L1,L2...L40 according to the i value in the loop.is it possible to do so?
0 件のコメント
回答 (2 件)
Vishwajith Upendra
2011 年 7 月 17 日
Here is a sample code which does what you want. Try it.
for i=1:5
x=num2str(i); % Converts number to string
x1=strcat('L',x); % Concatenates your prefix to the varying number
x1 % I guess, this is the variable you want
end
Hope it helped.
1 件のコメント
Oleg Komarov
2011 年 7 月 17 日
I think it's more likely to be the faq 4.6 as Walter suggested, otherwise the OP should be more specific.
Walter Roberson
2011 年 7 月 16 日
Why do you "need" to do this? There is almost always a better way.
3 件のコメント
Walter Roberson
2011 年 7 月 16 日
Sounds like a reason to use dynamic field names on a structure, and to use the '-struct' option of save()
この質問は閉じられています。
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!