Clear Filters
Clear Filters

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

Accepted Answer

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

Sign in to comment.

More Answers (1)

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

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!