HOW DO I USE AVERAGEIF(excel) IN MATLAB?

6 visualizaciones (últimos 30 días)
Sara Hill Osorio
Sara Hill Osorio el 7 de Oct. de 2021
Comentada: Sara Hill Osorio el 8 de Oct. de 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 comentarios
Simon Chan
Simon Chan el 7 de Oct. de 2021
Try function splitapply and refer to the example in the documentation
Sara Hill Osorio
Sara Hill Osorio el 7 de Oct. de 2021
Thank you! I will try!

Iniciar sesión para comentar.

Respuesta aceptada

Star Strider
Star Strider el 7 de Oct. de 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
.

Más respuestas (1)

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

Categorías

Más información sobre Tables en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by