Displaying loop index in a string

조회 수: 2 (최근 30일)
C Meek
C Meek 2012년 6월 28일
Hi all,
I'm just curious as to how to do this (or if it can even be done). If I'm using the input prompt in a loop, how can I get it to display the loop index in the string?
For example,
for k=1:NS
ele(k) = input('input value for ele(k)');
end
So essentially each time I would like this to say:
input value for ele(1)
input value for ele(2)...etc
Can this be done?
Thanks!
Craig

채택된 답변

Honglei Chen
Honglei Chen 2012년 6월 28일
input(sprintf('input value for ele(%d)',k))

추가 답변 (0개)

카테고리

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