Generate a N length vector from a M length list (permutation)
Afficher commentaires plus anciens
I have want to generate a 5-element vector:
A = [a1, a2, a3, a4, a5]
such that each element (a1...a5) could take on one of the three values [1, 2, 3];
There should be 3^5 number of outputs.
It should be easy but i have been trying for the last 90 minutes and got no luck.
4 commentaires
"...such that each element (a1...a5) could take on one of the three values [1, 2, 3]"
"Just to clarify. [1, 2, 3, 4, 5] and [1, 2, 3, 5, 4] should be two separate outputs"
Your examples include values that are not in the list of values that you want. Confusing.
Is 5 permitted (as per your example) or not (as per your explanation) ?
madhan ravi
le 2 Sep 2019
You still haven’t answered Stephen’s last question.
Yue Zhang
le 2 Sep 2019
Réponses (2)
Walter Roberson
le 2 Sep 2019
[Ac{1:5}] = ndgrid(1:3);
result = cell2mat(cellfun(@(M) M(:), Ac, 'uniform', 0));
1 commentaire
Yue Zhang
le 2 Sep 2019
Andrei Bobrov
le 2 Sep 2019
out = fullfact(3*ones(1,5));
Catégories
En savoir plus sur Logical 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!