Print for loop iterations with their specific label

조회 수: 5 (최근 30일)
Brian Sigler
Brian Sigler 2018년 12월 13일
댓글: Stephen23 2018년 12월 13일
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
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
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.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by