How to create a 2D reverse matrix

6 ビュー (過去 30 日間)
Anthony Koning
Anthony Koning 2022 年 10 月 17 日
編集済み: John D'Errico 2022 年 10 月 17 日
Hi, I'm wondering how to create a reversed numerical matrix. For example, if I have a convolution h[j,k] = [1 2 3; 4 5 6; 7 8 9] then reverse h[j,k] = h[-j-k] = [9, 8 7; 6 5 4; 3 2 1]. I'm aware that you can use rot90(h, 2) and a combination of fliplr and flipud to get the results of reverse h, but are there any more direct ways to get the reverse matrix? Thanks.

採用された回答

John D'Errico
John D'Errico 2022 年 10 月 17 日
編集済み: John D'Errico 2022 年 10 月 17 日
Since you are willing to use tools like fliplr (as opposed to flip. Anyway, fliplr and flipud are more descriptive, so I kind of like them.) But then what is wrong with the simple:
H = [1 2 3; 4 5 6; 7 8 9]
H = 3×3
1 2 3 4 5 6 7 8 9
Hflip = fliplr(flipud(H))
Hflip = 3×3
9 8 7 6 5 4 3 2 1
which requires only 2 calls. Or, if you like a matrix multiply, you could do it as:
trans = flip(eye(3));
trans*H*trans
ans = 3×3
9 8 7 6 5 4 3 2 1

その他の回答 (1 件)

David Hill
David Hill 2022 年 10 月 17 日
a=[1 2 3; 4 5 6; 7 8 9];
reshape(flip(a(:)),size(a))
ans = 3×3
9 8 7 6 5 4 3 2 1

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by