Homework problem: Write a Matlab function to calculate the body mass index (BMI) with the following function prototype:
function [BMI, status] = ComputeBMI(weight_kg, height_cm)
where the input weight_kg is the weight measured in kilograms and height_cm is the height measured in centimeters. The output BMI is the calculated BMI according to the inputs, and status should be 1, 2, 3, or 4 indicating the status of “underweight”, “normal or healthy weight”, “overweight”, or “obese”. Notice that the output BMI should be rounded to have precision to 0.1 and the status is determined according to BMI with this precision. For example, for a guy with weight of 68 kg and height of 165 cm, the output BMI should be 25.0 and the status should be 3 indicating “overweight”. Please refer to the webpage below for more info on BMI:
function [BMI, status] = ComputeBMI(weight_kg, height_cm)
%本代码可以实现输入身高体重后计算人体BMI(精确度为小数点后1位)数值
%并根据BMI数值的范围告知测试者身体状况
height_m = height_cm / 100;
%计算BMI数值,并进行四舍五入的保留一位小数
BMI = weight_kg / (height_m)^2;
BMI = roundn(BMI,-1);
%根据不同的BMI数值,规定status的数值
if BMI < 18.5
status = 1;
elseif BMI <= 24.9
status = 2;
elseif BMI <= 29.9
status = 3;
else
status = 4;
end
end