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

조회 수: 1 (최근 30일)
Mahdi
Mahdi 2013년 9월 24일
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
Azzi Abdelmalek
Azzi Abdelmalek 2013년 9월 24일
Then why are you asking to not use some functions?
Mahdi
Mahdi 2013년 9월 24일
편집: Mahdi 2013년 9월 24일
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

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by