I am trying to get user input for node coordinates. For some reason the ouput in the command window does not show the variable number, but instead a square:
Input
for i =1:2
x(i)=input(['coordinate for x ' i ' in metres: ']);
end
Output
coordinate for x in metres:

댓글 수: 1

Dr. Kelsey Joy
Dr. Kelsey Joy 2021년 11월 27일
편집: Dr. Kelsey Joy 2021년 11월 27일
num2str(i) so it doesn't just convert the number to a character position
I agree sprintf or fprintf may be a better approach.

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

 채택된 답변

Walter Roberson
Walter Roberson 2019년 1월 19일

0 개 추천

['coordinate for x ' i ' in metres: ']
Concatenation between a character and a numeric value is define the same as if you had done
['coordinate for x ', char(i), ' in metres: ']
char(1) is the unprintable SOH (Start of Header) character, and char(2) is the unprintable STX (Start Of Text) character.
You should look at sprintf(). Or switch to string objects:
"coordinate for x " + i + " in metres: "
is well defined as formatting the number as text (according to ill-defined rules.)

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Dates and Time에 대해 자세히 알아보기

제품

질문:

2019년 1월 19일

편집:

2021년 11월 27일

Community Treasure Hunt

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

Start Hunting!

Translated by