Matlab计算BMI数值与健康指标的函数

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:

有关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

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值