how to generate random matrix with known matrix
Afficher commentaires plus anciens
Hello Everyone, For example I have; a=[1 2 3]; b=[4 5]; s=8;
I can create matrix(es?) like this; matrix1=[a b s]; (ans=[1 2 3 4 5 8]) matrix2=[a s b]; (ans=[1 2 3 8 4 5]) matrix3=[s b a]; (ans=[8 4 5 1 2 3]) etc...
But how can I make Matlab generate all the possible (3!) combinations without writing them manually myself? Is it even possible? I am aware that it is not that hard to do with 6 different outcomes but I have (15!) combinations that I have to generate. I appriciate all answers. Thank you.
2 commentaires
David Goodmanson
le 12 Déc 2017
Hello Melike,
The perms function will give all possible permutations of the elements of a vector, and you could use that as a building block to get concatenated permutations of small row vectors. However, maybe you should think about the final result. 15! is approximately 1.31e12. Suppose the the average length of the small vectors is 2 and you generated all the results at once as implied above. Then even with everything stored as uint8, it takes39000 Gbytes of memory. That's a lot of memory.
If you only wanted to generate a few million of them or whatever at random, that's doable with the help of the randperm function.
Melike Öztürk
le 13 Déc 2017
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Logical dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!