permsk

版本 1.1 (1.8 KB) 作者: Jos (10584)
All permutations of K elements from an array (set)
64.0 次下载
更新时间 2019/4/22

查看许可证

P = permsk(S, K) returns all permutations of K elements taken from the set S with N elements. P will be a N!/(N-K)!-by-K array. Each row of P holds a unique permutation of K elements.
P will be of the same type as S, which can be any kind of array (numerical, char, string, struct, cell, etc.).

Example:
permsk(1:4, 2) % -> [ 1 2 ; 1 3 ; 1 4 ; 2 1 ; ...
... 3 2 ; 3 4 ; 4 1 ; 4 2 ; 4 3]

The list of permutations in the rows of P are ordered. To speed things up slightly, you can provide a third argument, like: permsk(S, K, 1), so a call to sortrows is skipped.
When K > N, P will be empty.

See also perms, nchoosek, randperm, permute.
permn, nchoose, nchoose2 (file Exchange)

引用格式

Jos (10584) (2024). permsk (https://www.mathworks.com/matlabcentral/fileexchange/71300-permsk), MATLAB Central File Exchange. 检索来源 .

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

Community Treasure Hunt

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

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

edited help section and improved comments

1.0.0