Indexing a Variable in an Input Prompt
조회 수: 4 (최근 30일)
이전 댓글 표시
I am trying to create and input statement that refrences a changing variable in my code.
Playerturn = 1
prompt = ('Player %i move x: ', Playerturn);
y1 = input(prompt, 's');
I'm able to print the input statement but it prints it as
Player %i move x:
instead of
Player 1 move x:
I have a while loop that changes the value of Playerturn back and forth between 1 and 2, how do I reference the variable in one input statement so that it can work for both players?
댓글 수: 0
답변 (2개)
Steven Lord
2019년 11월 21일
If you're using a release that supports string you can use the + operator for string.
Playerturn = 2;
moveNumber = 1;
y1 = input("Player " + Playerturn + " move " + moveNumber + ": ", 's')
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!