1D array combinations
Afficher commentaires plus anciens
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 commentaire
KSSV
le 23 Fév 2016
are you looking for something like the function perms?
doc perms
Réponse acceptée
Plus de réponses (1)
Jos (10584)
le 23 Fév 2016
Modifié(e) : Jos (10584)
le 23 Fév 2016
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:
Catégories
En savoir plus sur Descriptive Statistics dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!