MATLAB Answers

How to mirror matrix on the diagonal?

543 views (last 30 days)
SL
SL on 21 Oct 2016
Answered: Fady Samann on 13 Aug 2020
I want to mirror data matrix on the diagonal.
Input:
y
|
____ x
Expected output:
x
|_y
I know you these transformations but I cannot get mirror around the diagonal (y=x line from (0,0) to (1,1))
I = imread('onion.png');
I2 = flipdim(I ,2); %# horizontal flip
I3 = flipdim(I ,1); %# vertical flip
I4 = flipdim(I3,2); %# horizontal+vertical flip
MATLAB: 2016b OS: Debian 8.5

  2 Comments

Massimo Zanetti
Massimo Zanetti on 21 Oct 2016
Can you give a simple example with numeric array of the "mirroring" you need? Is it something like:
1 2 3
4 5 6
7 8 9
to
9 6 3
8 5 2
7 4 1
?
SL
SL on 21 Oct 2016
Yes, your example is valid.

Sign in to comment.

Accepted Answer

Thorsten
Thorsten on 21 Oct 2016
I2 = rot90(fliplr(I),-1);

  1 Comment

SL
SL on 21 Oct 2016
This is the only answer which work with big matrices.

Sign in to comment.

More Answers (2)

Massimo Zanetti
Massimo Zanetti on 21 Oct 2016
Edited: Massimo Zanetti on 21 Oct 2016
In the case described before it is:
A=[1 2 3;4 5 6;7 8 9]
rot90(A,2)'
which gives:
A= 1 2 3
4 5 6
7 8 9
to
9 6 3
8 5 2
7 4 1

  2 Comments

SL
SL on 21 Oct 2016
I get some ND error with big matrices with this method. I think this method does not work for non-square or something other type of data. What do you think?
Massimo Zanetti
Massimo Zanetti on 22 Oct 2016
I can't see why it shouldn't work... You must give me an example, otherwise I cannot understand. No problems with rectangular matrices.

Sign in to comment.


Fady Samann
Fady Samann on 13 Aug 2020
you can do the following:
first, transpose the matrix
A = table.';
Flip it horizontally
A = flip (A,1);
then, flip it verticaly
A = flip (A,2);

  0 Comments

Sign in to comment.

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by