need help on user-defined MATLAB function
Afficher commentaires plus anciens
What can i alter in my function file so this "ans " will not be displayed in the command window. Or how can i remove it?
My function file contains:
function [ height_cm, mass_kg ] = height_weight_conversion(height_ft, height_in, mass_lb)
% Determining the height in centimeters (cm) and mass in kilograms (kg)
% of a person from his height in inches (in.) and weight in pounds (lb).
% Inputs:
% height_ft = height in feet
% height_in = height in inches
% mass_lb = weight in pounds
% Outputs:
% height_cm = height in centimeters
% mass_lb = weight in kilograms
height_ft = input('Enter height in feet(ft):');
height_in = input('Enter height in inches(in):');
mass_lb = input('Enter mass in pounds(lb):');
% Converting height in feet to inches
ft_to_in = height_ft * 12;
% Calculating the height in inches to centimeters
height_cm = (ft_to_in + height_in) * 2.54;
% Calculating the weight in pounds to kilograms
mass_kg = mass_lb / 2.20462;
fprintf('The height is %.2f centimeters(cm) and weight is %.2f kilograms(kg)',height_cm,mass_kg)
end
Here's the pic of command window

Réponses (1)
Walter Roberson
le 20 Avr 2021
function [ Height_cm, Mass_kg ] = height_weight_conversion(height_ft, height_in, mass_lb)
% Determining the height in centimeters (cm) and mass in kilograms (kg)
% of a person from his height in inches (in.) and weight in pounds (lb).
% Inputs:
% height_ft = height in feet
% height_in = height in inches
% mass_lb = weight in pounds
% Outputs:
% height_cm = height in centimeters
% mass_lb = weight in kilograms
height_ft = input('Enter height in feet(ft):');
height_in = input('Enter height in inches(in):');
mass_lb = input('Enter mass in pounds(lb):');
% Converting height in feet to inches
ft_to_in = height_ft * 12;
% Calculating the height in inches to centimeters
height_cm = (ft_to_in + height_in) * 2.54;
% Calculating the weight in pounds to kilograms
mass_kg = mass_lb / 2.20462;
fprintf('The height is %.2f centimeters(cm) and weight is %.2f kilograms(kg)',height_cm,mass_kg)
if nargout > 0
Height_cm = height_cm;
Mass_kg = mass_kg;
end
end
Catégories
En savoir plus sur Dates and Time dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!