how to add combinatorics function in matlab with n different objects divided into r groups and each group get at least 1 object

3 views (last 30 days)
I have 7 machines which I want to group in 3 cells such that each cell contain atleast 1 machine the numeric formula for this is
I want to generate a matrix with each combination and run loop over that. is there any way I can code this? for example the 1st array is 1 1 1 1 2 3 1 and running the 2nd time loop give another value for example 1 1 1 2 1 1 3

Accepted Answer

Roger Stafford
Roger Stafford on 11 Jan 2017
C = zeros(r^n,n);
t = 0;
for k = 0:(r^n)-1
s = dec2base(k,r,n);
if length(unique(s))==r
t = t+1;
C(t,:) = s-0+1;
C = C(1:t,:);

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!