How to find average score of different combination
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi,
Below is my data (cell array),
Type Score Name Energy Dose
Auto 12 N 23 23
Auto 34 P 23 29
Semi 56 N 29 29
Auto 123 N 29 29
Auto 12 P 29 43
Semi 122 S 43 23
I want to find the average score of each combination(of Name,Energy, Dose) for Auto &Semi separatly.
Here the existing combinations are:(need to do it automatically)
DifferentNameSameEneryDifferentDose
DifferentNameDifferentEnergySameDose
SameNameSameEnerySameDose
DifferentNameDifferentEnergyDifferentDose
Desired Output:
Auto:
Combination AvgScore Count
DiffNameSameEneryDiffReap 23 2
SameNameSameEnerySameReap 123 1
Semi:
Combination AvgScore Count
DiffNameDiffEnergyDiffReap 122 1
DiffNameDiffEnergySameReap 56 1
0 comentarios
Respuestas (2)
Bernhard Suhm
el 9 de Dic. de 2017
Your combinations don't define a proper partition of the data sets.
The grpstats command does allow you to group data from a table by one or more columns. For example, grpstats(tbl,{'Type','Name','Energy'},'mean') will group your data (read into the variable 'tbl') by Type, and then Name and Energy.
1 comentario
Matt Tearle
el 12 de Dic. de 2017
Can you explain what you mean by "same" and "different" in this context, and how you're getting the output you want, because it's not clear. To me, "DifferentNameDifferentEnergySameDose", for example, would mean that you want to group by dose, so for "Auto" there'd be 3 groups: dose = 23, dose = 29, and dose = 43. The first and last group have a single element each, and the middle group has two elements:
Type Score Name Energy Dose Group
Auto 12 N 23 23 1
Auto 34 P 23 29 2
Semi 56 N 29 29
Auto 123 N 29 29 2
Auto 12 P 29 43 3
Semi 122 S 43 23
The average scores would then be three different values (one for each group): 12, (34+123)/2 = 78.5, 12.
But that doesn't appear to be what you're after. Your output has no such combination for "Auto" and one group for "Semi".
Your output also seems to include 5 total elements ("Count" = [2,1,1,1]), but the table has 6 entries. So how are you determining the combinations of "same" and "different"? (It's not all 8 possible combinations: SSS, SSD, SDS, SDD, DSS, DSD, DDS, DDD)
1 comentario
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!