k indexes from 1:n

版本 1.0.0.0 (1.6 KB) 作者: Maxim Vedenyov
Return matrix of all possible k indexes, it is C(n,k) variants
310.0 次下载
更新时间 2010/9/24

查看许可证

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

引用格式

Maxim Vedenyov (2024). k indexes from 1:n (https://www.mathworks.com/matlabcentral/fileexchange/28818-k-indexes-from-1-n), MATLAB Central File Exchange. 检索来源 .

MATLAB 版本兼容性
创建方式 R2009b
兼容任何版本
平台兼容性
Windows macOS Linux
类别
Help CenterMATLAB Answers 中查找有关 Matrix Indexing 的更多信息

Community Treasure Hunt

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

Start Hunting!
版本 已发布 发行说明
1.0.0.0