How to construct a matrix M1 with size of (2k − 2) × 1. M1 contains (k − 1) ones and (k − 1) zeros. For example, M1 = [1 1 1 0 0 0]T for k = 4. We obtain all possible permutations of M1, denoting Mi , i = 2, . . . ,N, where N = (2k−2)! (k−1)!(k−1)!
1 view (last 30 days)
Show older comments
PLACEIUS NISHIGA G
on 29 Dec 2017
Commented: PLACEIUS NISHIGA G
on 29 Dec 2017
How to construct a matrix M1 with size of (2k − 2) × 1. M1 contains (k − 1) ones and (k − 1) zeros. For example, M1 = [1 1 1 0 0 0]T for k = 4. We obtain all possible permutations of M1, denoting Mi , i = 2, . . . ,N, where N = (2k−2)! (k−1)!(k−1)!
0 Comments
Accepted Answer
KSSV
on 29 Dec 2017
k = 4 ;
N = 2*k-2 ;
O = ones(k-1,1) ;
Z = zeros(k-1,1) ;
% 0's and 1's in order
iwant = [O ; Z]
% 0's and 1's in random
iwant = randsample([O ; Z],N)
3 Comments
KSSV
on 29 Dec 2017
N = ((2k−2)!)/((k−1)!(k−1)!)....what is value of k in this case..and how many 1 and 0 you want?
PLACEIUS NISHIGA G
on 29 Dec 2017
i want (k-1)no of ones and zeros. we can choose k value as our need.for example k=3
More Answers (1)
Matt J
on 29 Dec 2017
k = 4 ;
N = 2*k-2 ;
I=nchoosek(1:N,k-1);
J=repmat( (1:size(I,1)).' ,1,size(I,2) );
M=accumarray([I(:),J(:)],1).';
0 Comments
See Also
Categories
Find more on Linear Algebra 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!