Multinomial matrix
Show older comments
I want to generate a multinomial matrix such that with given K(interger)>0 I can get a matrix with all the possible combination of K+1 variables whose sum is from 1 to K eg for K=3, we have x1, x2, x3, x4 variables
we should have
1 0 0 0
...
0 0 0 1
2 0 0 0
...
0 0 0 2
1 1 0 0
...
3 0 0 0
...
1 1 0 1
There should be total 34 rows/combination it is impossible to manually input if k increases I wonder if anyone can suggest a proper way/function to generate such a matrix?
Answers (1)
Bruno Luong
on 27 Feb 2011
K=3
allVL1(K+1,K,'<=')
ans =
0 0 0 0
0 0 0 1
0 0 1 0
0 1 0 0
1 0 0 0
0 0 0 2
0 0 1 1
0 0 2 0
0 1 0 1
0 1 1 0
0 2 0 0
1 0 0 1
1 0 1 0
1 1 0 0
2 0 0 0
0 0 0 3
0 0 1 2
0 0 2 1
0 0 3 0
0 1 0 2
0 1 1 1
0 1 2 0
0 2 0 1
0 2 1 0
0 3 0 0
1 0 0 2
1 0 1 1
1 0 2 0
1 1 0 1
1 1 1 0
1 2 0 0
2 0 0 1
2 0 1 0
2 1 0 0
3 0 0 0
Discard the first row if you don't need all-zero vector.
Categories
Find more on Multinomial Distribution 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!