How to find minimum and maximum values?

조회 수: 60 (최근 30일)
Ayob
Ayob 2014년 1월 28일
답변: nguyen an 2024년 3월 17일
I have to matrices A and B which both of them are p*q matrices. I want to compare each member of A and B like A(i,j) and B(i,j) and put the maximum in a matrix like C it the same position of (i,j) and the minimum in the other matrix like D in the same position of (i,j). I want to use MATLAB special features.

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2014년 1월 28일
C=max(A,B)
D=min(A,B)
  댓글 수: 2
Arturo Jr Bayangks
Arturo Jr Bayangks 2018년 9월 5일
what if you had more than 2 matrix ?
Stephen23
Stephen23 2018년 9월 5일
편집: Stephen23 2018년 9월 5일
@Arturo Jr Bayangks: for several matrices try this:
min(cat(3,A,B,C,...),[],3)
Clearly this would get unwieldy for lots of separate variables, which is why it is recommended to store such data in one cell array, e.g. X:
min(cat(3,X{:}),[],3)
Once you notice that cat just joins all of the data into one array then you might think to skip the stage of having lots of separate arrays altogether, and simply store your data in one array to start with, e.g. Y:
min(Y,[],3)
Then you are on your way to writing simpler, more efficient MATLAB code.
For ND arrays with more than 2 non-scalar dimensions, increase 3 to a suitable dimension.

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

추가 답변 (2개)

Thomas
Thomas 2014년 1월 28일
you can use min() & max() functions
min (matrix) %returns the minimum
max (matrix) %returns the maximum

nguyen an
nguyen an 2024년 3월 17일
how to find min max function?

카테고리

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

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by