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 1s:

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

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -