필터 지우기
필터 지우기

How can I find multiple maximum values and they are indexes of 4-D array

조회 수: 16 (최근 30일)
A
A 2018년 7월 16일
댓글: A 2018년 7월 17일
Hi every body, pleas who can help me to find the multiple values and they indexes of 4-D array ?
as an example below :
A(:,:,1,1)=
1 3 5
3 5 1
5 1 3
I want the output as :
max value= 5 , index (3,1,1,1)
max value= 5 , index (2,2,1,1)
max value= 5 , index (1,3,1,1)
My attempt to solve that is :
[max_val, Index] = max(A(:));
[A1,A2,A3,A4] = ind2sub(size(A),Index);
the output was:
max value= 5 , index =3
A1= 3
A2= 1
A3= 1
A4= 1
Which means only the first maximum value, but I want all values. Thank you in advance

채택된 답변

Nanditha Nirmal
Nanditha Nirmal 2018년 7월 16일
Hi,
You can try something like this:
maxval = max(A(:));
idx = find(A == maxval);
[A1,A2,A3,A4] = ind2sub(size(A),idx);
This should give all the max value indices.

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by