How can I create variables with for loop?
14 次查看(过去 30 天)
显示 更早的评论
I want somthing like this:
for i=1:3;
j`i'=i;
end
The output shuld be:
j1=1 j2=2 j3=3
thanks!
0 个评论
回答(3 个)
Ilham Hardy
2013-8-15
编辑:Ilham Hardy
2013-8-15
Use eval
To know more about eval function, type doc eval in your command window.
To know more about why you should avoid eval, wait an pay attention to comment on this answer :P
1 个评论
Jan
2013-8-15
Oh no, Ilham Hardy, do not suggest eval() never ever and under no circumstances. It is evil and eats up the programmers trials to write clear, clean and efficient code. There is always a better solutions. The topic has been discussed often enough and is found in the FAQs.
Satisfied? :-)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!