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

2 views (last 30 days)

Show older comments

##### 0 Comments

### 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 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.

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')

##### 0 Comments

### See Also

### Categories

### Community Treasure Hunt

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

Start Hunting!