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)!

采纳的回答

KSSV
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
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?

请先登录,再进行评论。

更多回答(1 个)

Matt J
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).';

类别

Help CenterFile Exchange 中查找有关 Linear Algebra 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by