# How to find average score of different combination

6 ビュー (過去 30 日間)
Mekala balaji 2017 年 12 月 9 日
コメント済み: Mekala balaji 2017 年 12 月 15 日
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

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

### 回答 (2 件)

Bernhard Suhm 2017 年 12 月 9 日
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 件のコメント表示非表示 なし
Mekala balaji 2017 年 12 月 9 日

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

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

Matt Tearle 2017 年 12 月 12 日
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 件のコメント表示非表示 なし
Mekala balaji 2017 年 12 月 15 日
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
NA NA NA NANANA
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.

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

### カテゴリ

Find more on Descriptive Statistics in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by