Trying to find the number of people overweight gives zero

2 ビュー (過去 30 日間)
Victor
Victor 2023 年 10 月 19 日
コメント済み: Dyuman Joshi 2023 年 10 月 21 日
% Read data from the Excel file
data = xlsread('bodyInfo.xlsx');
% Extract columns
Gender = data(:, 2); % 0: Male, 1: Female
Height = data(:, 3); % measured in cm
Weight = data(:, 4); % measured in KG
% Calculate BMI
BMI = (703 * Weight) ./ (Height.^2);
% (a) Calculate average BMI for male group and standard deviation for female group
avg_BMI_male = mean(BMI(Gender == 0));
std_BMI_female = std(BMI(Gender == 1));
% (b) Determine the number of males classified as 'Overweight'
overweight_males = sum(Gender == 0 & BMI >= 25 & BMI < 30);
% (c) Determine the number of females classified as 'Obese'
obese_females = sum(Gender == 1 & BMI >= 30);
% Display the results
fprintf('Average BMI for Male: %.2f\n', avg_BMI_male);
fprintf('Standard Deviation of BMI for Female: %.2f\n', std_BMI_female);
fprintf('Number of Males classified as Overweight: %d\n', overweight_males);
fprintf('Number of Females classified as Obese: %d\n', obese_females);
  2 件のコメント
Dyuman Joshi
Dyuman Joshi 2023 年 10 月 19 日
There might not be any data in that particular category.
Why are you multiplying by 703 to find the BMI? And not converting the height to meters?
Jon
Jon 2023 年 10 月 19 日
Please attach your input .xlsx file so we can run your code

サインインしてコメントする。

回答 (1 件)

the cyclist
the cyclist 2023 年 10 月 19 日
I agree with @Jon that uploading your data file will help, but the problem is almost certainly what @Dyuman Joshi hints at, which is that you are most likely not using the correct formula for BMI, given the units of your inputs.
The formula
BMI = (703 * Weight) ./ (Height.^2);
is a correct one, but appropriate only when using Imperial units (weight measured in pounds and height measured in inches).
According to the comments in your code, you have Weight in kilograms and Height in centimeters. So, I believe you need
BMI = (Weight) ./ ((Height/100).^2);
  4 件のコメント
Sam Chak
Sam Chak 2023 年 10 月 19 日
@Victor, do you plot the chart or histogram as well?
Dyuman Joshi
Dyuman Joshi 2023 年 10 月 21 日
Any updates? @Victor

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeClassification についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by