Find all matlab maximum indexes

I just want to find all the indices of the maximum value in a vector in matlab. the max function returns only the index of the first occurrence of the maximum. For instance:

maxChaqueCell = [4 5 5 4] [maximum, indicesDesMax] = max(maxChaqueCell) maximum = 5 indicesDesMax = 2 

I need indicesDesMax have 2 and 3, which are the indices of the two 5 that we have in maxChaqueCell , how can I do this?

Thanks.

+6
source share
2 answers

First you find the maximum value, then you will find all the elements equal to it:

 m = max(myArray); maxIndex = find(myArray == m); 

Or using variable names:

 maxChaqueCell = [4 5 5 4]; maximum = max(maxChaqueCell) indicesDesMax = find( maxChaqueCell == maximum ); 

Here's how you find them, not just the first one.

+9
source
 [value,index] = sort(maxChaqueCell,'descend'); sortedmaximums = [value,index]; 
+1
source

Source: https://habr.com/ru/post/947371/


All Articles