k indexes from 1:n
http://simulations.narod.ru/
Using:
ind=all_combinations(n,k)
Number of all posible variants is nv=C(n,k)=n!/(k!*(n-k)!) (binomial coefficient)
ind is nv-by-k matrix. Example, 2 indexes from 1 2 3:
all_combinations(3,2)
ans =
1 2
1 3
2 3
Example 3 from 5:
all_combinations(5,3)
ans =
1 2 3
1 2 4
1 2 5
1 3 4
1 3 5
1 4 5
2 3 4
2 3 5
2 4 5
3 4 5
Cite As
Maxim Vedenyov (2024). k indexes from 1:n (https://www.mathworks.com/matlabcentral/fileexchange/28818-k-indexes-from-1-n), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform Compatibility
Windows macOS LinuxCategories
Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
Version | Published | Release Notes | |
---|---|---|---|
1.0.0.0 |