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

21 次查看(过去 30 天)
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 中查找有关 Matrix Indexing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by