Flipping a matrix diagonally
83 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I would like to flip a matrix that I have diagonally from left to right as shown in the image. Is there a command or a simple way to do this? The other two ends of my matrices have the correct values so I do not want them to move![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/676633/image.jpeg)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/676633/image.jpeg)
0 Kommentare
Akzeptierte Antwort
DGM
am 7 Jul. 2021
Bearbeitet: DGM
am 7 Jul. 2021
I'm assuming you want to flip the whole matrix diagonally
To flip about the southeast-northwest diagonal is just transpose:
A = magic(5)
A.'
So then flipping about the opposite diagonal is just a matter of flipping one axis:
fliplr(fliplr(A).')
2 Kommentare
DGM
am 8 Jul. 2021
I don't see how that's possible with any rigid transformation like a flip/transpose/rotation. The fact that adjacent corners become opposite corners leads me to question what you expect the interior of the array to look like.
Consider:
A = [147 278;
457 13];
becomes
B = [457 147;
278 13];
B is basically A' with the top row flipped. What if there were more rows?
A = [147 156 278;
124 456 583;
457 46 13];
We could transpose and then ...? How do you half-flip a row?
B = [457 124 147;
??? ??? ???;
278 583 13];
I'm not really sure what this transformation is supposed to do. I mean anything is possible with interpolation, but the question is what it means.
Weitere Antworten (1)
KSSV
am 7 Jul. 2021
A = rand(5) ;
n = size(A,1) ;
v = A(1:n+1:end) ;
A(1:n+1:end) = fliplr(A(1:n+1:end))
Also read about diag.
1 Kommentar
Siehe auch
Kategorien
Mehr zu Matrix Indexing 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!