필터 지우기
필터 지우기

get maximum value of four arrays

조회 수: 1 (최근 30일)
john
john 2011년 3월 19일
Hello
I am trying to compare the same elements of four arrays of the same size.For example,I have created arrays GM1,GM2,GM3,GM4 of size(x,y). And I want to create a final array with element (1,1) the maximum of GM1(1,1),GM2(1,1),GM3(1,1),GM4(1,1) and making the same for elements final(1,2) and the rest.I have created the following code but I cannot get any result.Could somebody help me with this?
Thanks in advance
===========code=============== for i=1:x for j=1:y
m=GM1(i,j);
if(GM2(i,j)>m) m=GM2(i,j);
if(GM3(i,j)>m) m=GM3(i,j);
if(GM4(i,j)>m) m=GM4(i,j);
final(i,j)=m;
end;
end;

채택된 답변

Sean de Wolski
Sean de Wolski 2011년 3월 19일
max(cat(3,GM1,GM2,GM3,GM4),[],3)

추가 답변 (1개)

Jan
Jan 2011년 3월 19일
For large arrays this consumes less memory:
max(max(GM1, GM2), max(GM3, GM4))

카테고리

Help CenterFile Exchange에서 Operators and Elementary Operations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by