HOW DO I USE AVERAGEIF(excel) IN MATLAB?

12 Ansichten (letzte 30 Tage)
Sara Hill Osorio
Sara Hill Osorio am 7 Okt. 2021
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 :
  2 Kommentare
Simon Chan
Simon Chan am 7 Okt. 2021
Try function splitapply and refer to the example in the documentation
Sara Hill Osorio
Sara Hill Osorio am 7 Okt. 2021
Thank you! I will try!

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Star Strider
Star Strider am 7 Okt. 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
.

Weitere Antworten (1)

Steven Lord
Steven Lord am 7 Okt. 2021
Take a look at the groupsummary function.

Kategorien

Mehr zu Tables finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by