need help on user-defined MATLAB function

3 ビュー (過去 30 日間)
Jezreel Gamez
Jezreel Gamez 2021 年 4 月 20 日
回答済み: Walter Roberson 2021 年 4 月 20 日
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

回答 (1 件)

Walter Roberson
Walter Roberson 2021 年 4 月 20 日
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

カテゴリ

Help Center および File ExchangeDates and Time についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by