How to create permutations of multisets?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Vasilis Chasiotis
am 16 Mai 2020
Bearbeitet: Ameer Hamza
am 16 Mai 2020
I have a vector with N=6 elements and q=3 elements symboled as 0, 1, 2.
I want to create all vectors consisted of N=6 elements such that:
- 2 elements out of N=6 are equal to 0,
- 2 elements out of N=6 are equal to 1,
- 2 elements out of N=6 are equal to 2
in all possible positions.
How can I create them?
The number of these vectors are equal to 90, that is:
[1,] 0 0 1 1 2 2
[2,] 0 0 1 2 1 2
[3,] 0 0 1 2 2 1
[4,] 0 0 2 1 1 2
[5,] 0 0 2 1 2 1
[6,] 0 0 2 2 1 1
[7,] 0 1 0 1 2 2
[8,] 0 1 0 2 1 2
[9,] 0 1 0 2 2 1
[10,] 0 1 1 0 2 2
[11,] 0 1 1 2 0 2
[12,] 0 1 1 2 2 0
[13,] 0 1 2 0 1 2
[14,] 0 1 2 0 2 1
[15,] 0 1 2 1 0 2
[16,] 0 1 2 1 2 0
[17,] 0 1 2 2 0 1
[18,] 0 1 2 2 1 0
[19,] 0 2 0 1 1 2
[20,] 0 2 0 1 2 1
[21,] 0 2 0 2 1 1
[22,] 0 2 1 0 1 2
[23,] 0 2 1 0 2 1
[24,] 0 2 1 1 0 2
[25,] 0 2 1 1 2 0
[26,] 0 2 1 2 0 1
[27,] 0 2 1 2 1 0
[28,] 0 2 2 0 1 1
[29,] 0 2 2 1 0 1
[30,] 0 2 2 1 1 0
[31,] 1 0 0 1 2 2
[32,] 1 0 0 2 1 2
[33,] 1 0 0 2 2 1
[34,] 1 0 1 0 2 2
[35,] 1 0 1 2 0 2
[36,] 1 0 1 2 2 0
[37,] 1 0 2 0 1 2
[38,] 1 0 2 0 2 1
[39,] 1 0 2 1 0 2
[40,] 1 0 2 1 2 0
[41,] 1 0 2 2 0 1
[42,] 1 0 2 2 1 0
[43,] 1 1 0 0 2 2
[44,] 1 1 0 2 0 2
[45,] 1 1 0 2 2 0
[46,] 1 1 2 0 0 2
[47,] 1 1 2 0 2 0
[48,] 1 1 2 2 0 0
[49,] 1 2 0 0 1 2
[50,] 1 2 0 0 2 1
[51,] 1 2 0 1 0 2
[52,] 1 2 0 1 2 0
[53,] 1 2 0 2 0 1
[54,] 1 2 0 2 1 0
[55,] 1 2 1 0 0 2
[56,] 1 2 1 0 2 0
[57,] 1 2 1 2 0 0
[58,] 1 2 2 0 0 1
[59,] 1 2 2 0 1 0
[60,] 1 2 2 1 0 0
[61,] 2 0 0 1 1 2
[62,] 2 0 0 1 2 1
[63,] 2 0 0 2 1 1
[64,] 2 0 1 0 1 2
[65,] 2 0 1 0 2 1
[66,] 2 0 1 1 0 2
[67,] 2 0 1 1 2 0
[68,] 2 0 1 2 0 1
[69,] 2 0 1 2 1 0
[70,] 2 0 2 0 1 1
[71,] 2 0 2 1 0 1
[72,] 2 0 2 1 1 0
[73,] 2 1 0 0 1 2
[74,] 2 1 0 0 2 1
[75,] 2 1 0 1 0 2
[76,] 2 1 0 1 2 0
[77,] 2 1 0 2 0 1
[78,] 2 1 0 2 1 0
[79,] 2 1 1 0 0 2
[80,] 2 1 1 0 2 0
[81,] 2 1 1 2 0 0
[82,] 2 1 2 0 0 1
[83,] 2 1 2 0 1 0
[84,] 2 1 2 1 0 0
[85,] 2 2 0 0 1 1
[86,] 2 2 0 1 0 1
[87,] 2 2 0 1 1 0
[88,] 2 2 1 0 0 1
[89,] 2 2 1 0 1 0
[90,] 2 2 1 1 0 0
0 Kommentare
Akzeptierte Antwort
Ameer Hamza
am 16 Mai 2020
Bearbeitet: Ameer Hamza
am 16 Mai 2020
Try this
x = [0 0 1 1 2 2];
M = unique(perms(x), 'rows');
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Operators and Elementary Operations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!