Return matrix of maximum values

조회 수: 2 (최근 30일)
Manu Mensa
Manu Mensa 2019년 2월 20일
댓글: Manu Mensa 2019년 2월 21일
I have a matrix of the form:
a =
17 24 1 8 15
23 5 7 14 16
4 6 13 20 22
10 12 19 21 3
11 18 25 2 9
column 1 & 2 represent x,y positions while col 3-5 represent intensity. I obtained the maximum and index of the intensity for each position from [M,I] =max(a(:,3:5),[],1). I am struggling with how to obtain the x,y positions corresponding to each maximum intensity. Any help would be appreciated. Thanks.
  댓글 수: 2
madhan ravi
madhan ravi 2019년 2월 20일
explicitly write your desired output
Manu Mensa
Manu Mensa 2019년 2월 20일
Thank you very much.

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

채택된 답변

madhan ravi
madhan ravi 2019년 2월 20일
  댓글 수: 4
Stephen23
Stephen23 2019년 2월 21일
편집: Stephen23 2019년 2월 21일
Or without intermediate variables:
>> [M,I] = max(a(:,3:5),[],1);
>> XY = [a(I,1),a(I,2)]
XY =
11 18
10 12
4 6
Manu Mensa
Manu Mensa 2019년 2월 21일
Thank you all very much. It worked.

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

추가 답변 (1개)

Jos (10584)
Jos (10584) 2019년 2월 20일
maxxy = zeros(3, 2) ; % pre-allocation
for k = 1:3
[~, r] = max(M(:, k+2)) ; % row of maximum value in column k
maxxy(k, :) = M(r, [1 2]) ;
end
  댓글 수: 1
Manu Mensa
Manu Mensa 2019년 2월 21일
Thank youy very much.

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

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by