How to determine number of patients in the category

I am trying to determine how many patients fall into each BMI class and each blood pressure class. Like how many patients are "Normal", how many are "Overweight", etc. and how many have normal bp or high bp, etc. Here is the table I have formulated. It is named data_table. I am stuck on how to count the patients.

回答 (2 件)

Voss
Voss 2025 年 3 月 17 日

1 投票

data_table = table([1;2;3;4;5;6],[24;26;25;28;27;26],["Underweight";"Optimal";"Obese";"Obese";"Obese";"Optimal"],["Low";"Normal";"Normal";"Pre Hypertension";"Stage 1 Hypertension";"Normal"],'VariableNames',{'ID','Age','BMI Class','Blood Pressure Class'})
data_table = 6x4 table
ID Age BMI Class Blood Pressure Class __ ___ _____________ ______________________ 1 24 "Underweight" "Low" 2 26 "Optimal" "Normal" 3 25 "Obese" "Normal" 4 28 "Obese" "Pre Hypertension" 5 27 "Obese" "Stage 1 Hypertension" 6 26 "Optimal" "Normal"
result = groupcounts(data_table,{'BMI Class','Blood Pressure Class'})
result = 5x4 table
BMI Class Blood Pressure Class GroupCount Percent _____________ ______________________ __________ _______ "Obese" "Normal" 1 16.667 "Obese" "Pre Hypertension" 1 16.667 "Obese" "Stage 1 Hypertension" 1 16.667 "Optimal" "Normal" 2 33.333 "Underweight" "Low" 1 16.667
Reference:
These may also be useful:
Star Strider
Star Strider 2025 年 3 月 17 日

0 投票

Use the accumarray function.
Try something like this —
imshow(imread('Screenshot 202....55.14 PM.png'))
BMIC = ["Underweight","Optimal","Obese"];
T = table(Size =[10,1], VariableTypes={'string'}, VariableNames={'BMI Class'});
T.('BMI Class') = BMIC(randi(3,10,1)).'
T = 10x1 table
BMI Class _____________ "Obese" "Underweight" "Underweight" "Obese" "Optimal" "Underweight" "Optimal" "Obese" "Optimal" "Obese"
[Cu,~,idx] = unique(T.('BMI Class'))
Cu = 3x1 string array
"Obese" "Optimal" "Underweight"
idx = 10×1
1 3 3 1 2 3 2 1 2 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
Tally = accumarray(idx, ones(size(idx)))
Tally = 3×1
4 3 3
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
Result = table(Cu,Tally)
Result = 3x2 table
Cu Tally _____________ _____ "Obese" 4 "Optimal" 3 "Underweight" 3
.

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

製品

リリース

R2024b

タグ

質問済み:

2025 年 3 月 17 日

回答済み:

2025 年 3 月 17 日

Community Treasure Hunt

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

Start Hunting!

Translated by