How to find out how many participants are in each group of my combined matrix (31230x5)

2 views (last 30 days)
I need to analyse how many participants are in each group and print a bar graph displaying this information. So I want to extract the amount of participants (participant IDs are in column 1) are in each group (groups 1-8 are in column 2) For example, participant 1 in group 1 is column 1 row 1-53. Participant 1 in group 2 is column 1 row 3993-4108. There are around 40 participants in each group. I just can’t work out how I can extract this information and put group number 1-8 on x-axis and how many participants on y-axis

Answers (2)

dpb on 21 Jan 2023
Edited: dpb on 21 Jan 2023
If I understand the description, the end result is easiest via
hH=histogram(categorical(M(:,2))); % display histogram of number participants in each group
xlabel('Group'), ylabel('Number in Group')
hH.Values % echo the category counts to screen
But, there seems a dichotomy in the description and the total number that is not consistent -- if there are 8 groups of roughly 40 participants/group, that's only 8*40 --> 320 distinct participants. How did you get roughly 100X times that number for the total vector length? There's got to be something else going on that isn't would presume there are other grouping/categorizing variable in the remaining columns to break down the number of participants in the subgroups to about that number -- but, unless there are repeated trials (which would be another type of grouping), then it's not possible.
Jazmine on 21 Jan 2023
Yes i see your is repeated measures, a factor i really shouold of included in this messgage! My apologise. I combined all 8 groups into 1 large matrix, so there are roughly 320 participants.

Sign in to comment.

Voss on 21 Jan 2023
% some data like yours with participant IDs in column 1
% and group ID in column 2:
data = [randi(40,31230,1) randi(8,31230,1)];
% count the number of particpants in each group:
[groups,group_IDs] = findgroups(data(:,2));
num_participants_by_group = groupsummary(data(:,1),groups,@(x)numel(unique(x)));
% plot bar graph:
ylabel('# of Participants')

Community Treasure Hunt

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

Start Hunting!