How to find minimum of every two columns and rows?
조회 수: 6 (최근 30일)
이전 댓글 표시
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
채택된 답변
Walter Roberson
2021년 12월 27일
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!