Generate permutations of numbers

조회 수: 4(최근 30일)
Afz
Afz 2012년 9월 2일
I am using this perms([0 1]) to generate permutations and its giving me the following result
1 0
0 1
I want it to generate the all possible combinations e.g
1 1
1 0
0 1
0 0
i also used nchoosek([0 1],2) but i got
0 1
I want to generate similar type of combinations for 5 variables (1,2,3,4,5) where the range include 4 numbers.e.g
1 1 1 1 1
1 1 1 1 2
1 1 1 1 3 ...... It would be total of 4^5 = 1024 unique combinations. Thanks

채택된 답변

Matt Fig
Matt Fig 2012년 9월 2일
편집: Matt Fig 2012년 9월 2일
You can use my npermutek.
npermutek([0 1],2)
ans =
0 0
0 1
1 0
1 1
Also, for the general problem see combinator.
  댓글 수: 1
Afz
Afz 2012년 9월 2일
Thankyou

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

추가 답변(0개)

범주

Find more on Discrete Math in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by