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

4 views (last 30 days)
Jazmine on 21 Jan 2023
Commented: Jazmine on 21 Jan 2023
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

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 described....one 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.
dpb on 21 Jan 2023
Well,that's not going to be so...the only way there are only the roughly 40 participants in a group is when the grouping is by all repeated measures.
If the particpants are assigned by group before the other measures begin and not randomized and no participants are added nor lost to the experiment, then the number in each group will be the same across the other various measures -- training class, trial number and attempts. But, if any of those are an uneven number of any of those properties (that is, some participants don't have all three training levels or number of trials or the number of attempts isn't always the same), then the number per group won't be identical for every breakdown possible.
Clearly if there are 31,000 individual records that you're counting, the sum of the number of participants by the number of groups has to total that many; the only way you can have roughly 320 total participants is when you only count roughly 320 unique records out of the total 32000 in one grouping.
Jazmine on 21 Jan 2023
Yes i see your point....it 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.

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:
bar(group_IDs,num_participants_by_group)
xlabel('Group')
ylabel('# of Participants')

### Categories

Find more on Noncentral t Distribution 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!