how to calculate bmi in matlab

To calculate Body Mass Index (BMI) in MATLAB, you can use the formula:

BMI = weight(kg) / (height(m))^2

Here's an example code that takes weight and height as inputs, and returns the calculated BMI:

main.m
weight = input('Enter weight in kg: ');
height = input('Enter height in meters: ');

BMI = weight / (height)^2;

disp(['Body Mass Index (BMI) calculated is: ',num2str(BMI)]);

if BMI < 18.5
    disp('You are underweight');
elseif BMI >= 18.5 && BMI < 25
    disp('You have a normal weight');
elseif BMI >= 25 && BMI < 30
    disp('You are overweight');
else
    disp('You are obese');
end
389 chars
17 lines

In this code, we also added a BMI classification based on the World Health Organization's (WHO) BMI classification system to determine if a person is underweight, normal weight, overweight, or obese.

gistlibby LogSnag