Finding highs in a vector using MATLAB

I am trying to find the local maxima of a number vector using MATLAB. The built-in findpeaks function will work for a vector, for example:

[0 1 2 3 2 1 1 2 3 2 1 0] 

where the peaks (each of 3 's) occupy only one position in the vector, but if I have a vector:

 [0 1 2 3 3 2 1 1 2 3 2 1 0] 

the first "peak" takes two positions in the vector, and the findpeaks function findpeaks not pick it.

Is there a good way to write a maximization function that detects such peaks?

+4
source share
3 answers

You can use the REGIONALMAX function in the Image Processing Toolbox:

 >> x = [0 1 2 3 3 2 1 1 2 3 2 1 0] x = 0 1 2 3 3 2 1 1 2 3 2 1 0 >> idx = imregionalmax(x) idx = 0 0 0 1 1 0 0 0 0 1 0 0 0 
+3
source
 a = [ 0 1 2 3 3 2 1 2 3 2 1 ]; sizeA = length(a); result = max(a); for i=1:sizeA, if a(i) == result(1) result(length(result) + 1) = i; end end 

result contains max, followed by all values ​​equal to max.

-1
source

Something is much simpler:

 a = [1 2 4 5 5 3 2]; b = find(a == max(a(:))); 

output:

 b = [4,5] 
-1
source

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


All Articles