compare the elements of multiple matrix and return min and max matrix

조회 수: 2 (최근 30일)
Hi everyone, I want to compare the matrixes A, B, C and find the min and max values for the same index;
A = [1 92 33;
4 15 66;
16 27 48]
B = [34 45 16;
67 38 19;
2 83 31]
C = [20 53 61;
4 17 83;
35 14 39]
and return to two matrixes such as,
Min = [1 45 16;
4 15 19;
2 14 31]
Max = [34 92 61;
67 88 83;
35 83 48]
How can I get this result? Could you please help with this?

채택된 답변

Star Strider
Star Strider 2019년 5월 29일
First concatenate them, then do the min and max calls:
ABC = cat(3,A,B,C);
Min = min(ABC,[],3)
Max= max(ABC,[],3)
producing:
Min =
1 45 16
4 15 19
2 14 31
Max =
34 92 61
67 38 83
35 83 48
  댓글 수: 3
Steven Lord
Steven Lord 2019년 5월 29일
FYI you can use bounds to compute Min and Max in one call.
[theMin, theMax] = bounds(ABC, 3)
Star Strider
Star Strider 2019년 5월 29일
@Steven — Noted. I have used bounds. I just forgot about it here.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Kevin Phung
Kevin Phung 2019년 5월 29일
A = [1 92 33;
4 15 66;
16 27 48];
B = [34 45 16;
67 38 19;
2 83 31];
C = [20 53 61;
4 17 83;
35 14 39];
D = cat(3,A,B,C);
Dmin = min(D,[],3)
Dmax = max(D,[],3)

카테고리

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