Print for loop iterations with their specific label
3 次查看(过去 30 天)
显示 更早的评论
How can I get a for loop to print the specific iteration number it is on? For example I'm using a for loop to print the Fourier series coefficient, which I can do no problem, but rather than each print out be "an=", "an=", "an=", etc, how can I make it that each label is printing and incrementing, such as "a1=", "a2=", "a3=", etc. I apologize if the language of this request is confusing but hopefully the example I used is clear enough.
1 个评论
Stephen23
2018-12-13
If you want to display that information then use fprintf or sprintf.
If you want to magically change variable names inside a loop then read this:
回答(1 个)
madhan ravi
2018-12-13
Don't think of naming variables dynamically but if it's for your label then sprintf()(lookup in the documentation) should do it.
0 个评论
另请参阅
类别
在 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!