Mean for certain conditions

조회 수: 1 (최근 30일)
Anna
Anna 2021년 2월 7일
편집: Anna 2021년 2월 10일
Hello,
I hope I can express my problem right, if not please ask about further details.
I am quite the beginner so I already have problems 'translating' the following basics into matlab language:
I have a table with data of a rating experiment and I need to get the mean values of certain items.
For each ID (all the '2' lines are one subject) I need a mean for the four ratings of the four phases of each snack and item. For example, I want the mean of the ratings of phases 1-4 for the item 'wanting' for the snack 'Gummibärchen', and that for each subject. ANd that for all items and snacks.
The plan after that is to visualise those differnces in heatmaps or plots but I am not sure how my desired output should look like (e.g. list or table or?). If you have tips regarding this, that would be great, too.
I have included a table with the data of 2 test IDs for testing, if that helps.
(Because the table is quite long, this screenshot only shows the beginnign of the table but as you can see the first 8 lines are all the 'Gummibärchen' ratings for phase 1 with the 8 rating-items. After that follows the same for 'Crackers', etc. Then, after the 6 snacks it switches back to 'Gummibärchen' and starts phase 2...)
Thank you for your help!

채택된 답변

Ive J
Ive J 2021년 2월 7일
편집: Ive J 2021년 2월 7일
t = readtable('extracted_table.xlsx');
y = groupsummary(t, {'ID', 'Item', 'Snack'}, @mean, 'Rating'); % mean of Rating for each ID, Item and Snack combination
head(y)
ID Item Snack GroupCount fun1_Rating
__ ______________ _________________ __________ ___________
2 {'Bitternis' } {'Brezeln' } 4 1.5367
2 {'Bitternis' } {'Cracker' } 4 0.44025
2 {'Bitternis' } {'Gummibaerchen'} 4 3.4337
2 {'Bitternis' } {'Kekse' } 4 0.28776
2 {'Bitternis' } {'Nic Nacs' } 4 1.8572
2 {'Bitternis' } {'Rosinen' } 4 5.322
2 {'Intensität'} {'Brezeln' } 4 52.593
2 {'Intensität'} {'Cracker' } 4 32.14
You can visualize it also with scatter3
scatter3(categorical(y.Item), categorical(y.Snack), y.fun1_Rating, 50, y.ID, 'filled')
c = colorbar(gca);
c.Ticks = unique(y.ID);
c.TickLabels = string(unique(y.ID)); % show IDs on the colorbar
  댓글 수: 1
Anna
Anna 2021년 2월 7일
Awesome, thank you!
I totally overlooked the groupsummary function as I was always just looking at how to do it with the mean function.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Standard File Formats에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by