Get exact indices of max value in 3D matrix

8 Ansichten (letzte 30 Tage)
Hampus Alfredsson
Hampus Alfredsson am 14 Mär. 2018
Kommentiert: Hampus Alfredsson am 14 Mär. 2018
I have a 3D matrix like the one below:
A(:,:,1) = [30 31 32 33 34];
A(:,:,2) = [29 35 27 23 20];
I want to get the indices for the maximum value (which is 35). So i write:
[r,c,p] = find(A==max(max(A))), and get the following result:
r = 1, c = 7, p = 1
I want the answer to be:
r = 1, c = 2, p = 2...
How can I do this?
  1 Kommentar
Stephen23
Stephen23 am 14 Mär. 2018
find does not return the page dimension, as you tried: the third output argument is actually the non-zero values themselves.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Stephen23
Stephen23 am 14 Mär. 2018
Bearbeitet: Stephen23 am 14 Mär. 2018
Use ind2sub:
>> A(:,:,1) = [30 31 32 33 34];
>> A(:,:,2) = [29 35 27 23 20];
>> [mxv,idx] = max(A(:));
>> [r,c,p] = ind2sub(size(A),idx)
r = 1
c = 2
p = 2
Note that using the linear index idx to access the data may be more efficient.

Weitere Antworten (0)

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by