필터 지우기
필터 지우기

Flipping a matrix diagonally

조회 수: 83 (최근 30일)
Curtis Lam
Curtis Lam 2021년 7월 7일
댓글: Isobel 2023년 1월 25일
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

채택된 답변

DGM
DGM 2021년 7월 7일
편집: DGM 2021년 7월 7일
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 = 5×5
17 24 1 8 15 23 5 7 14 16 4 6 13 20 22 10 12 19 21 3 11 18 25 2 9
A.'
ans = 5×5
17 23 4 10 11 24 5 6 12 18 1 7 13 19 25 8 14 20 21 2 15 16 22 3 9
So then flipping about the opposite diagonal is just a matter of flipping one axis:
fliplr(fliplr(A).')
ans = 5×5
9 3 22 16 15 2 21 20 14 8 25 19 13 7 1 18 12 6 5 24 11 10 4 23 17
  댓글 수: 2
Curtis Lam
Curtis Lam 2021년 7월 8일
I think this is close but for some reason it's not working correctly for me.. right now I have a 500x500 matrix with vertices ( the corners) looking like
[ 147 278
457 13.6]
and i want to flip/rotate the matrix so that the corners are these values so i know that the matrix is accurately representative of the raw data with corners like so:
[457 147
278 13.6]
I think I may have worded the question incorrectly but your answer might be right for the question i asked.
DGM
DGM 2021년 7월 8일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

KSSV
KSSV 2021년 7월 7일
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
Isobel
Isobel 2023년 1월 25일
This flips the diagonal, not the matrix along the diagonal.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by