In: Computer Science
Write a user-defined MATLAB function, with two input and two output arguments that determines the height in centimeters (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.
===============================================================
Matlab Script to copy:
% Matlab script to convert given mesurements into SI units
%(a) height and mass of a 5 ft.15 in. person who weight 180 lb in SI units
feetToInches = 5 * 12; % Converting feets to inches
height = feetToInches + 15; % Total height in inches
mass = 180; % Mass in pounds(lb)
[heightInCm, weightInKg] = measuresInSI(height, mass);
disp("Output (a):")
fprintf("Height in centimeters: %.2f", heightInCm)
fprintf("Weight in kilograms: %.2f", weightInKg)
%(b) My own height and weight in SI units
feetToInches = 5 * 12; % Converting feets to inches
height = feetToInches + 10; % Total height in inches
mass = 135; % Mass in pounds(lb)
[heightInCm, weightInKg] = measuresInSI(height, mass);
disp("Output (b):")
fprintf("Height in centimeters: %.2f", heightInCm)
fprintf("Weight in kilograms: %.2f", weightInKg)
function [height, weight] = measuresInSI(inches, pounds)
height = inches * 2.54; % 1 inch = 2.54 centimeters
weight = pounds * 0.45359237; % 1 pound(lb) = 0.45359237 kg
end
------------------------------------------------------------
Matlab script screenshot:
-------------------------------------------------------
Sample Output:
===================================================================
Hope it will helpfull and do comments for any additional info if needed. Thankyou
===================================================================