how to generate random matrix with known matrix
Show older comments
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 Comments
David Goodmanson
on 12 Dec 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
on 13 Dec 2017
Accepted Answer
More Answers (0)
Categories
Find more on Logical in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!