Is this what you want?
numUsers = 50;
N_UE = 1 : numUsers
s = N_UE(randperm(length(N_UE)))
numGroups = 5;
divisions = sort(randperm(numUsers-2, numGroups-1) + 1, 'ascend')
divisions = [0, divisions, numUsers]
groups = cell(1, numGroups);
for k = 1 : numGroups
indexes = divisions(k)+1:divisions(k+1);
usersInThisGroups = length(indexes);
fprintf('Assigning %d users (indexes %d to %d) to group %d.\n', ...
usersInThisGroups, divisions(k)+1,divisions(k+1), k);
groups{k} = s(indexes);
end
celldisp(groups);
You'll see
Assigning 19 users (indexes 1 to 19) to group 1.
Assigning 5 users (indexes 20 to 24) to group 2.
Assigning 7 users (indexes 25 to 31) to group 3.
Assigning 9 users (indexes 32 to 40) to group 4.
Assigning 10 users (indexes 41 to 50) to group 5.
groups{1} =
20 17 10 12 4 9 32 13 50 49 23 15 41 26 37 28 6 47 43
groups{2} =
22 31 7 35 29
groups{3} =
18 11 8 44 42 38 46
groups{4} =
30 36 33 24 19 2 45 5 34
groups{5} =
21 1 16 39 14 27 48 40 3 25
You have 5 groups and in each group is a random number of users chosen from the entire group of 50 users. The users in each group are randomly chosen (not sequentially taken) from the larger, entire group of 50. Every user is in exactly one and only one group, and no user is missing. Change numUsers and numGroups as needed for your situation.
Best Answer