Flipping a matrix diagonally
Mostrar comentarios más antiguos
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

Respuesta aceptada
Más respuestas (2)
Ramdev Rajeshbhai Gohil
el 12 de Sept. de 2024
0 votos
Hi. To flip the matrix diagonally as required by you....it will have to go through the following sequence:
flip-transpose-flip-transpose
or
transpose-flip-transpose-flip
Any of these will work for both square or rectangular matrices.
So the code will be:
A=fliplr((fliplr(A'))');
Thanks.
1 comentario
Consider the 2x2 example that was given;
% the stated input
A = [147 278
457 13];
% the stated output
B0 = [457 147
278 13];
% this output
B = fliplr((fliplr(A'))')
That doesn't match the requested output.
Consider the quadrilateral connecting the array corners ABCD:

The specified output maps these corner positions ABCD to DACB. This folded quadrilateral isn't the product of any number of rigid transformations (rotation, flip, transpose).

Of course, we could do this transformation, but when presented as a 2x2 array, it's not clear what's intended to happen on the interior of the array. Consider the standard cameraman.tif image. We could just pad the rows with some value:

... or we could stretch the rows to fit?

... or we could do any number of discontinuous things to meet the constraints at the corners.
It's hard for me to come up with a scenario where either seems useful.
OP never clarified, but I suspect that the original example is just a mistake. It's anybody's guess what was intended, so you might even be right.
Categorías
Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!