Picking elements from a set

版本 1.0.0.0 (1.5 KB) 作者: Stefan Stoll
Gives all possibilities of picking k elements from a set of N with/without order/repetition.
3.3K 次下载
更新时间 2006/10/23

无许可证

s = pick(V,k,Type)

Gives all possibilities of picking k elements from the set V with or without order and repetition.
V can be an array of any size and any type.
Type can have the following values: '', 'o', 'r', 'or'. 'o' means pick ordered list, 'r' means replace elements after picking.

s is an array with all picks, one per row.

Examples:

>> pick(0:1, 4, 'or')
ans =
0 0 0 0
0 0 0 1
0 0 1 0
0 0 1 1
0 1 0 0
0 1 0 1
0 1 1 0
0 1 1 1
1 0 0 0
1 0 0 1
...

>> pick('abcd', 2, '')
ans =
ab
ac
ad
bc
bd
cd

>> pick(1:3,3,'o')
ans =
1 2 3
1 3 2
2 1 3
2 3 1
3 1 2
3 2 1

引用格式

Stefan Stoll (2024). Picking elements from a set (https://www.mathworks.com/matlabcentral/fileexchange/12724-picking-elements-from-a-set), MATLAB Central File Exchange. 检索来源 .

MATLAB 版本兼容性
创建方式 R14
兼容任何版本
平台兼容性
Windows macOS Linux
类别
Help CenterMATLAB Answers 中查找有关 Data Distribution Plots 的更多信息
致谢

启发作品: VChooseK, VChooseKR, VChooseKO

Community Treasure Hunt

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

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