How to find minimum of every two columns and rows?

1 view (last 30 days)
Ammy
Ammy on 27 Dec 2021
Commented: Ammy on 27 Dec 2021
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

Accepted Answer

Walter Roberson
Walter Roberson on 27 Dec 2021
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.

More Answers (1)

Matt J
Matt J on 27 Dec 2021
Edited: Matt J on 27 Dec 2021
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.

Community Treasure Hunt

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

Start Hunting!