Azzera filtri
Azzera filtri

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

16 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

Nanditha Nirmal
Nanditha Nirmal il 16 Lug 2018
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.

Più risposte (0)

Categorie

Scopri di più su Matrices and Arrays in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by