variable name by cancatation in matlab
1 次查看(过去 30 天)
显示 更早的评论
I want to set
c1=1;
c2=4;
c3=9;
c4=16;
How to do this in the following way
for i=1:4
ci=i^2;
end
i.e i will vary to generate c1, c2, c3, c4 etc. from ci.
0 个评论
回答(1 个)
Image Analyst
2014-8-7
编辑:Image Analyst
2014-8-7
Don't use separate variables with different names. Use an array:
ci = [1:4].^2
If you really want to do it the for loop way, do this:
for k = 1 : 4
c(k) = k ^2;
end
2 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!