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 CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by