HOW DO I USE AVERAGEIF(excel) IN MATLAB?

조회 수: 12 (최근 30일)
Sara Hill Osorio
Sara Hill Osorio 2021년 10월 7일
댓글: Sara Hill Osorio 2021년 10월 8일
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일
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일
Take a look at the groupsummary function.

카테고리

Help CenterFile Exchange에서 Tables에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by