Using a variable in an input prompt

조회 수: 180 (최근 30일)
lsutiger1
lsutiger1 2015년 11월 6일
댓글: lsutiger1 2015년 11월 6일
I am trying to use the iterator (ii) of my for loop as a string in my input prompt. The code is shown below
for ii = 1:n
x = input('What is the orientation of molecule ' num2str(ii) 'in the x-direction?');
end
but this does not work. Any suggestions?
  댓글 수: 1
lsutiger1
lsutiger1 2015년 11월 6일
Thank you to all who replied! Much appreciated!!

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2015년 11월 6일
x = input(['What is the orientation of molecule ' num2str(ii) 'in the x-direction?']);

추가 답변 (1개)

Wanbin Song
Wanbin Song 2015년 11월 6일
Input argument of 'input' function should be a text.
Your code shows that your input arguments of 'input' function consists of three string.
Just combine them as below.
for ii = 1:n
x = input(['What is the orientation of molecule ' num2str(ii) 'in the x-direction?']);
end
Then it will work.

Community Treasure Hunt

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

Start Hunting!

Translated by