How to find minimum of every two columns and rows?

15 ビュー (過去 30 日間)
Ammy
Ammy 2021 年 12 月 27 日
コメント済み: Ammy 2021 年 12 月 27 日
Let A =randi(16,4);
A =
14 11 16 16
15 2 16 8
3 5 3 13
15 9 16 3
First I want to find minimum of every two column that is min(column1,column2) , min(column3,column4) in each row. Let the output be B
B=[11 16;2 8;3 3;9 3]
And then I want to find minimum of every two rows that is min(row1,row2) min(row3,row4) in each column. let the output be C
C=[2 8;3 3];
1- How can I get C for any n*n matrix?
2- Can I get the original matrix back with the help of C?
Any help in this regard will be much appreciated.
Thanks

採用された回答

Walter Roberson
Walter Roberson 2021 年 12 月 27 日
A = [14 11 16 16; 15 2 16 8; 3 5 3 13; 15 9 16 3]
A = 4×4
14 11 16 16 15 2 16 8 3 5 3 13 15 9 16 3
B = reshape(min(reshape(A.', 2, [])), [], size(A,1)).'
B = 4×2
11 16 2 8 3 3 9 3
C = reshape(min(reshape(B, 2, [])), [], size(B,2))
C = 2×2
2 8 3 3
How can I get C for any n*n matrix
You cannot. The output is not defined for matrix with an odd number of rows or columns.
Can I get the original matrix back with the help of C?
No. Even if you had B to work with, not just C, you would not be able to tell that the upper left corner was not (say) 99 or 132.
If you had been taking the minimum of every two rows of A instead of from B then some values might be more constrained -- but if that was what you were doing, you would not be able to tell that A(2,1) was not any value greater than 14.

その他の回答 (1 件)

Matt J
Matt J 2021 年 12 月 27 日
編集済み: Matt J 2021 年 12 月 27 日
1 - How can I get C for any n*n matrix?
If you download sepblockfun
then it will just be,
C=sepblockfun(B,[2,2],'min');
2- Can I get the original matrix back with the help of C?
No, it's not a reversible process.
  1 件のコメント
Ammy
Ammy 2021 年 12 月 27 日
Thanks a lot for your valuable comments.

サインインしてコメントする。

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by