Line | |
---|
1 | %combnext Returns the next combination in order of shifting the least left |
---|
2 | %number to the right. |
---|
3 | % |
---|
4 | % function next=combnext(n, k, com) |
---|
5 | % |
---|
6 | %n and k has the meaning of combination number. |
---|
7 | function next=combnext(n, k, com) |
---|
8 | |
---|
9 | next=com; |
---|
10 | move=k; moved=0; |
---|
11 | while ~moved |
---|
12 | if next(move) < n-k+move |
---|
13 | next(move)=next(move)+1; |
---|
14 | for i=move+1:k |
---|
15 | next(i)=next(move)+i-move; |
---|
16 | end |
---|
17 | moved=1; |
---|
18 | else |
---|
19 | if move>1 |
---|
20 | move=move-1; |
---|
21 | else |
---|
22 | disp('Error: this code should have never be called'); |
---|
23 | end |
---|
24 | end |
---|
25 | end |
---|
26 | |
---|
27 | return |
---|
28 | |
---|
Note: See
TracBrowser
for help on using the repository browser.