Displaying a value in a sentence

22 views (last 30 days)
Andrew Whyte
Andrew Whyte on 18 Jul 2018
Edited: KALYAN ACHARJYA on 30 Jul 2018
Hello, I am very new to Matlab and I am trying to make a simple FPS to MPH calculator. The code I have now goes as follows:
function [] =Fps_to_Mph()
prompt = 'How fast? (in FPS): ';
x = input(prompt);
y=(x/5280)/0.000277;
end
However, I want the output to say "(value): MPH" and I am not sure how to do that.
Thanks for any help.
  10 Comments
dpb
dpb on 18 Jul 2018
"\n (newline) is needed for fprintf ..."
Yeah, would have been better to written
disp('Your value is %0.1f MPH.',y)
but I was just editing in-place...

Sign in to comment.

Answers (1)

KALYAN ACHARJYA
KALYAN ACHARJYA on 18 Jul 2018
Edited: KALYAN ACHARJYA on 30 Jul 2018
%If you want to display y
fprintf('The value is %.2f MPH \n',y);
%here 2 means up to 2 floating points, if you need more for an exact value, change the value
  6 Comments
Image Analyst
Image Analyst on 30 Jul 2018
To clarify, the 2 in %.2f means two places to the right of the decimal points, and however many places to the left of the decimal place are needed. One floating point number, y, will be written into the string.
KALYAN ACHARJYA
KALYAN ACHARJYA on 30 Jul 2018
Edited: KALYAN ACHARJYA on 30 Jul 2018
True sir, I mistakenly mentioned the numbers, it should be up to two points. Thanks for the correction. I edited the comment

Sign in to comment.

Categories

Find more on Shifting and Sorting Matrices in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!