MATLAB: How grouping of users can be done

ofdma

N_UE=[1 2 3 4 5 6 7 8 9 10]
If there are 10 users in the system i need to form 5 groups such that 2 users are present in each group.
Could anyone help me how it can done using the commands.

Best Answer

Is this what you want?
numUsers = 50;
N_UE = 1 : numUsers
% Get a scrambled array
s = N_UE(randperm(length(N_UE)))
numGroups = 5; % Need to divide s up into 5 groups
divisions = sort(randperm(numUsers-2, numGroups-1) + 1, 'ascend')
divisions = [0, divisions, numUsers]
% Create cell array with random number of users in each groups
groups = cell(1, numGroups);
for k = 1 : numGroups
indexes = divisions(k)+1:divisions(k+1);
% Assign users to the kth group:
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); % Display groups in command window.
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.