How to find minimum of every two columns and rows?
6 views (last 30 days)
Show older comments
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
0 Comments
Accepted Answer
Walter Roberson
on 27 Dec 2021
A = [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)).'
C = reshape(min(reshape(B, 2, [])), [], size(B,2))
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.
0 Comments
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!