If I have a vector [1 2 3] and I want all combinations of these values along 6 elements so I will have (3^6) combinations in one vector, How can I do?
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Ahmed Ibrahim
le 31 Mai 2017
Réponse apportée : Guillaume
le 31 Mai 2017
If I have a vector [1 2 3] and I want all combinations of these values along 6 elements so I will have (3^6) combinations in one vector, How can I do?
0 commentaires
Réponse acceptée
Guillaume
le 31 Mai 2017
Most likely there's already an implementation on the FileExchange. Otherwise, it's easy to implement:
elements = [1 2 3];
count = 6;
combs = cell(1, count);
[combs{:}] = ndgrid(elements);
combs = reshape(cat(count + 1, combs{:}), [], count)
0 commentaires
Voir également
Catégories
En savoir plus sur Logical dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!