how to scramble positions of a matrix?
Afficher commentaires plus anciens
Hello, I've been trying to scramble the positions of a matrix. I have generated two sequences which help us to scramble the positions of the matrix. Eg;
X=[1 3 2 4]
Y=[3 4 1 2]
ie (X,Y) is used to scramble the positions of a 4x4 matrix
Let A= 56 77 228 99
88 31 52 21
32 74 90 28
66 99 42 33
now using the above two vectors i have the following order
B= (1,3) (1,4) (1,1) (1,2)
(3,3) (3,4) (3,1) (3,2)
(2,3) (2,4) (2,1) (2,2)
(4,3) (4,4) (4,1) (4,2)
ie
B= 228 99 56 77
90 28 32 74
52 21 88 31
42 33 66 99.
in addition i would also like to know how i can reverse the positions again ie th first element should be placed at (1,3). please help thanks in advance
Réponse acceptée
Plus de réponses (1)
Andrei Bobrov
le 7 Sep 2014
Aout = B(X,Y)
1 commentaire
Roger Stafford
le 7 Sep 2014
That works only because the two permutations Abirami selected each happened to be their own inverse. Of the 24 possible permutations of 1:4 fourteen are not their own inverse. For example, if X is [4 1 3 2], then X(X) is [2 4 3 1], therefore X is not its own inverse, and B(X,Y) would not return A.
Catégories
En savoir plus sur Creating and Concatenating Matrices 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!