MATLAB: I’m struggling to get fprintf to work

beginners exercisefprintf

Hi,
I've decided to learn how to code in MATLAB in my spare time. I've been working through some exercises and I've been working on the following problem.
Problem
Write a user-defined MATLAB function, with two input and two output arguments that determines the height in centimetres (cm) and mass in kilograms (kg)of a person from his height in inches (in.) and weight in pounds (lb).
(a) Determine in SI units the height and mass of a 5 ft.15 in. person who weight 180 lb.
(b) Determine your own height and weight in SI units.
I've managed to get the script to calculate my outputs correctly however, I can't get fprintf to work. I am able to output the variables with the disp command but I want to have both text and numbers displayed. Also would someone be able to have a look over this and let me know if this was the best approach to take when solving this problem.
Thank you!
function [ cheight , kweight ] = bodyconversion ( fheight , iheight , lweight )
%convert the weight of a person from lb's to kg's and the height from ft
%and inches to cm's
%fheight = height in feet, iheight = feet in inches and lweight = weight in
%lbs
fheight = input ( 'Enter your height in feet here: ' ) ;
iheight = input ( 'Enter your height in inches here: ' ) ;
lweight = input ( 'Enter your weight in pounds here: ' ) ;
%conversion formula for feet to inches is in = ft * 12
convertin = fheight * 12 ;
%conversion formula from inches to centimeters is: cm = inch * 2.54
% where height in inches includes feet.
cheight = ( convertin + iheight ) * 2.54 ;
% convert weight from lbs to kg formula is 1kg = 2.205 lbs
kweight = lweight / 2.205 ;
fprintf ( '%.5 ft, %5 in is %.5cm\n' , fheight , iheight , cheight ) ;
fprintf ( '%.5 lbs is %.5 kg\n' , lweight , kweight )
end

Best Answer

in aa format you need the % to mark the beginning of aa substitution . Then you might have some flag characters. After that you might have aa number indicating the field width . That can be followed by aa period and then the number of digits after the decimal place.
Now After all those and not optional is the conversion specification letter that says what kind of format to use . d for decimal, c for character , f for floating point , e for exponential , g for general , and so on.
You forgot to put in the conversion letter .