MATLAB Answers


How to find average score of different combination

Asked by Mekala balaji on 9 Dec 2017
Latest activity Commented on by Mekala balaji on 15 Dec 2017
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)
Desired Output:
Combination AvgScore Count
DiffNameSameEneryDiffReap 23 2
SameNameSameEnerySameReap 123 1
Combination AvgScore Count
DiffNameDiffEnergyDiffReap 122 1
DiffNameDiffEnergySameReap 56 1


Sign in to comment.

2 Answers

Answer by Bernhard Suhm on 9 Dec 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 Comment

My combination is based on: (Name,Energy,Dose), then calculate the average score for "Auto" case and "Semi" case separately.

Sign in to comment.

Answer by Matt Tearle
on 12 Dec 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 Comment

Hi, Same or different is based on previous data and current data. For example under energy column, row2 & row1 is same then I label as sameEnergy, whereas row3 is different from row2 (29 is not same as 23), then I label as different. Likewise in each column. Then I combine all. as below:
Name Energy Dose Combination
DiffName SameEnergy DiffDose DiffNameSameEnergyDiffDose
DiffName DiffEnergy SameDose DiffNameDiffEnergySameDose
SameName SameEnergy SameDose SameNameSameEnergySameDose
DiffName SameEnergy DiffDose DiffNameSameEnergyDiffDose
DiffName DiffEnergy DiffDose DiffNameDiffEnergyDiffDose
Then I calculate separet for auto and Semi cases.

Sign in to comment.