Borrar filtros
Borrar filtros

A loop for scanning all binary sequences of length n with k 1's and n-k 0's

1 visualización (últimos 30 días)
I want to write a loop that scans all binary sequences of length n with k 1's and n-k 0's.
Actually, in each iteration an action is performed on the sequence, then it goes to next sequence, if necessary. (I'm not looking for the functions like nchoosek or perms that return all such a sequences).
How to write such a loop? Thanks
  4 comentarios
Azzi Abdelmalek
Azzi Abdelmalek el 24 de Sept. de 2013
Then why are you asking to not use some functions?
Mahdi
Mahdi el 24 de Sept. de 2013
Editada: Mahdi el 24 de Sept. de 2013
Because for large n's it takes so much time (if memory allows) to return all such strings. But producing one by one is practical since as soon as the criterion is satisfied the loop will broke. Also, in this way no surplus computations are performed, increasing efficiency of my approach. Thanks

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by