User input and print question

조회 수: 10 (최근 30일)
triztyme
triztyme 2016년 4월 19일
답변: triztyme 2016년 4월 23일
I have the following code that I want it to print "Air density = x.xx kg/m^3" and "Blade radius = x.xx cm." Is it possible to add the 'kg/m^3' and 'cm' so it prints after the user entered numbers or should I be using a different input prompt?
density = input('Air density = ');
radius = input('Blade radius = ');

답변 (2개)

Renato Agurto
Renato Agurto 2016년 4월 19일
편집: Renato Agurto 2016년 4월 19일
Try using fprintf with \b (backspace) to "remove" the newline
density = input('Air density = ');
fprintf('\b kg/m^3\n');
radius = input('Blade radius = ');
fprintf('\b cm\n');
  댓글 수: 1
Walter Roberson
Walter Roberson 2016년 4월 19일
I have not seen any terminal since the ADM3A on which backspace removed a newline.

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


triztyme
triztyme 2016년 4월 23일
So here's what I ended up doing:
density = input('Enter air density in kg/m^3: ');
fprintf(outputfile,'Air density = %5.3f kg/m^3',density);
radius = input('Enter blade radius in cm: ');
fprintf(outputfile,'\nBlade radius = %2i cm',radius);
thanks for taking a look

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by