HOW DO I USE AVERAGEIF(excel) IN MATLAB?

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 件のコメント

Simon Chan
Simon Chan 2021 年 10 月 7 日
Try function splitapply and refer to the example in the documentation
Sara Hill Osorio
Sara Hill Osorio 2021 年 10 月 7 日
Thank you! I will try!

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

 採用された回答

Star Strider
Star Strider 2021 年 10 月 7 日

0 投票

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
.

その他の回答 (1 件)

Steven Lord
Steven Lord 2021 年 10 月 7 日

0 投票

Take a look at the groupsummary function.

カテゴリ

ヘルプ センター および File ExchangeMATLAB についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by