find min or max value element from more than two matrices

조회 수: 13 (최근 30일)
Sanaz
Sanaz 2014년 6월 2일
댓글: Sanaz 2014년 6월 2일
I know how we can find min or max value element from two matrices. For more than two matrices we can do two by two and then compare but I was wondering if there is any other simple way to find min or max value element from more than two matrices?

채택된 답변

George Papazafeiropoulos
George Papazafeiropoulos 2014년 6월 2일
편집: George Papazafeiropoulos 2014년 6월 2일
% data
matrix1=rand(2);
matrix2=rand(3);
matrix3=rand(4);
% engine
c=nan(4,4,3);
c(1:2,1:2,1)=matrix1;
c(1:3,1:3,2)=matrix2;
c(1:4,1:4,3)=matrix3;
% result
d=min(c,[],3)
e=max(c,[],3)
  댓글 수: 3
Image Analyst
Image Analyst 2014년 6월 2일
Are you sure? It's not what you asked for. You didn't say that you wanted an array of maxes and an array of mins after the individual arrays were all lined up in the upper left corner. And the values will depend on where you align the smaller matrices over the larger matrices.
Sanaz
Sanaz 2014년 6월 2일
I changed it a little bit and I used that like: a=rand(3,3); b=rand(3,3); c=rand(3,3); d(:,:,1)=a;d(:,:,2)=b;d(:,:,3)=c; and the minimum=min(d,[],3) (the result has the same size of a or b or c).

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

추가 답변 (1개)

Image Analyst
Image Analyst 2014년 6월 2일
For 3 matrices, you can do
minValue = min([a(:);b(:);c(:)])
maxValue = max([a(:);b(:);c(:)])
It's easy to see how to adapt it for more matrices.
  댓글 수: 2
dpb
dpb 2014년 6월 2일
편집: Image Analyst 2014년 6월 2일
Good 'un to use (:) to avoid the dimensions problem...don't know why didn't think of it. I removed the sorrier response.
Star Strider
Star Strider 2014년 6월 2일
Much more efficient.
+1

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by