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 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
KSSV
2017-12-29
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 个评论
KSSV
2017-12-29
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
2017-12-29
i want (k-1)no of ones and zeros. we can choose k value as our need.for example k=3
更多回答(1 个)
Matt J
2017-12-29
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 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!