How to find minimum of every two columns and rows?

조회 수: 11 (최근 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.

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by