randomly grouping cells in cell array
이전 댓글 표시
so i have a cell array with names of people and i want to make a function that generate random groups out of those names.
i want to make it so that grouping{1} in main function would return first group randomly chosen
i have 22 people and if i want to separate into 6 groups, i want 4 groups of 4 people and 2 groups of 3 people.
i have a main function that defines cell array defined as Identifiers that contains all 22 people names as character.
i'm not sure how to use that Identifiers into this function below. this is how far i have. this only returns array with empty 6 cells like {1x4 double}.
function grouping = generate_random_grouping(number_of_people, number_of_groups)
randorder = randperm(number_of_people); %shuffle the people
split = repmat(floor(number_of_people / number_of_groups), 1, number_of_groups); %how many in each group?
toincrease = mod(number_of_people, number_of_groups); %how many groups need an extra element
split(1:toincrease) = split(1:toincrease) + 1;
grouping = mat2cell(randorder, 1, split);
end
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!