Help with the equation in making groups.

i cant think of a syntax to do this.
for example #students : 43
min number of students per group: 2 max number of students per group: 3
%there will be 13 groups with 3 members and 2 groups with 2 members.
what if min =3, max = 4?
%there will be 10 groups with 4 members and 1 group with 3.
and so on. it differs depending on the given. i cant think of a syntax for this. :/

답변 (1개)

Andrei Bobrov
Andrei Bobrov 2012년 9월 30일
편집: Andrei Bobrov 2012년 9월 30일

0 개 추천

min1 = 2;
max1 = 3;
s = 43;
ns = fullfact(floor(s./[min1 max1]));
out = ns(find(ns*[min1 max1]' == s);
OR without fullfact
min1 = 2;
max1 = 3;
s = 43;
ns = floor(s./[min1 max1]);
[x y] = ndgrid(1:ns(1),1:ns(2));
ns1 = [x(:) y(:)];
out = ns1(ns1*[min1 max1]' == s,:);

댓글 수: 4

Portgas Ace
Portgas Ace 2012년 9월 30일
what is full fact?
Andrei Bobrov
Andrei Bobrov 2012년 9월 30일
fullfact - function from Statistics Toolbox
Portgas Ace
Portgas Ace 2012년 9월 30일
fullfact doesn't work in my matlab. :(
Andrei Bobrov
Andrei Bobrov 2012년 9월 30일
see part OR in my answer

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

태그

질문:

2012년 9월 30일

Community Treasure Hunt

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

Start Hunting!

Translated by