1D array combinations
显示 更早的评论
Hi all,
I have a 1D array containing numbers from 1 to 5.
A = [1
2
3
4
5]
How can I find all possible combinations (without doubles), so that...
B = [1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
2
2 3
etc.]
I tried a number of combinators from the FEX but they don't give me the result I'm after.
Thanks!
1 个评论
KSSV
2016-2-23
are you looking for something like the function perms?
doc perms
采纳的回答
更多回答(1 个)
Jos (10584)
2016-2-23
编辑:Jos (10584)
2016-2-23
My function NCHOOSE will create those combinations without (slowly) looping over nchoosek. Each combination is stored in a cell. The cell array can be easily transformed into a 2D array by padding the entries with NaNs using PADCAT.
C = nchoose(1:5)
A = padcat(C{:})
NCHOOSE and PADCAT can be downloaded here:
类别
在 帮助中心 和 File Exchange 中查找有关 Descriptive Statistics 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!