How to write cyclic permutation as an array in matlab?
Show older comments
I have disjoint permutation cycles such as (1 4 6 2 5 7 8 3)(9 10) means
1 comes under 4th position, 4 will be at 6th position ,6 will be at 2nd position and so on. 3 will be at first position .(9,10) means that 9 will ne at 10 position and 10 will be placed at 9th position.(Look at the second row of the output given below)
S=[1:10; 3 6 8 1 2 4 5 7 10 9];
out put is
1 2 3 4 5 6 7 8 9 10
3 6 8 1 2 4 5 7 10 9
It is easy when we have small permutation, but for large set like
perm=[22, 35, 17, 9, 11, 23, 56, 43, 25, 19, 26, 15, 28, 30, 6, 1, 33, 24, 12, 14, 47, 18, 20, 31, 41, 39, 32, 27, 34, 13, 21, 4, 2, 16, 8, 49, 7, 38, 40, 29, 10, 3, 5, 36, 42, 37, 44, 46, 48, 50];
required=[1:50;6 4 10 21 3 30 45 16 17 29 9 24 34 12 26 2 35 47 25 18 13 50 11 33 43 19 32 15 40 28 20 39 1 27 22 5 42 7 41 38 31 36 23 37 49 44 14 46 8 48 ];
output is
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
6 4 10 21 3 30 45 16 17 29 9 24 34 12 26 2 35 47 25 18 13 50 11 33 43 19 32 15 40 28 20 39 1 27 22 5 42 7 41 38 31 36 23 37 49 44 14 46 8 48
Is there a way in matlab that we can fill up the second row for large pemutation it is difficult to write manually.
Thanks in advance
Accepted Answer
More Answers (0)
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!