Matlab: Matrix with all combinations of 0s and 1s with at least k 1s in each row -
so choose row length, n, , each row contain 0s , 1s , have @ least k 1s. have matrix possible combinations in matlab.
for example, n=3 k=2:
1 1 0
1 0 1
0 1 1
1 1 1
you can use dec2bin
create of bit patterns , keep patterns correct number of 1
s:
n = 3; k = 2; allcombs = dec2bin( (2^k-1):(2^n-1) ) - '0'; % use -'0' convert integers outcombs = allcombs(sum(allcombs, 2) >= k, :); outcombs = 0 1 1 1 0 1 1 1 0 1 1 1
Comments
Post a Comment