MATLAB Answers

HOW DO I USE AVERAGEIF(excel) IN MATLAB?

10 views (last 30 days)
Hello, so I am new to Matlab and I am doing a project where I have to find the average of my column "weights" depending on the column "sex". So it is pretty much finsing the average weight of males and females. This is how the table looks like :

Accepted Answer

Star Strider
Star Strider on 7 Oct 2021
The groupsummary function is also an option —
g = {'Male';'Female'};
allSamples = table(randi([60 99],20,1),randi([160 210],20,1),g(randi([1,2],20,1)), 'VariableNames',{'Weight','Height','Sex'})
allSamples = 20×3 table
Weight Height Sex ______ ______ __________ 74 169 {'Female'} 90 165 {'Female'} 62 167 {'Female'} 82 170 {'Female'} 72 179 {'Male' } 63 207 {'Female'} 89 189 {'Female'} 90 188 {'Female'} 86 170 {'Female'} 88 177 {'Male' } 79 185 {'Male' } 81 197 {'Male' } 65 163 {'Female'} 89 163 {'Male' } 65 206 {'Female'} 70 168 {'Male' }
G = groupsummary(allSamples, 'Sex','mean','Weight')
G = 2×3 table
Sex GroupCount mean_Weight __________ __________ ___________ {'Female'} 12 77 {'Male' } 8 80.875
.

More Answers (1)

Steven Lord
Steven Lord on 7 Oct 2021
Take a look at the groupsummary function.

Community Treasure Hunt

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

Start Hunting!

Translated by