How to count the number of peaks in a graph? -graphic analysis-

I have this curve that contains certain peaks - I want to know how to get the number of these peaks.

Data examples

0.10 76792 0.15 35578 0.20 44675 0.25 52723 0.30 27099 0.35 113931 0.40 111043 0.45 34312 0.50 101947 0.55 100824 0.60 20546 0.65 114430 0.70 113764 0.75 15713 0.80 83133 0.85 79754 0.90 17420 0.95 121094 1.00 117346 1.05 22841 1.10 95095 1.15 94999 1.20 18986 1.25 111226 1.30 106640 1.35 34781 1.40 66356 1.45 68706 1.50 21247 1.55 117604 1.60 114268 1.65 26292 1.70 88486 1.75 89841 1.80 49863 1.85 111938 

The first column is the X value, the second is the y value.

I want to write a macro or formula that will tell me how many peaks in this graph.

Note: this graph is actually pegged and exported from Matlab, so if there is a way, I can say that my code will do this for me from matlab, that would also be great!

+7
source share
1 answer

if your data was in A1:B36 , then this formula =SUMPRODUCT(--(B2:B35>B1:B34),--(B2:B35>B3:B36))
returns 11 peaks

He checks if

  • B2 higher than B1 and B3 if he considers it a peak
  • then if B3 higher than B2 and B4 , if this is considered as a peak, etc.

enter image description here

[Updated: added VBA request]

 Sub GetMax() Dim chr As ChartObject Dim chrSeries As Series Dim lngrow As Long On Error Resume Next Set chr = ActiveSheet.ChartObjects(1) Set chrSeries = chr.Chart.SeriesCollection(1) On Error GoTo 0 If chrSeries Is Nothing Then Exit Sub For lngrow = 2 To UBound(chrSeries.Values) - 1 If chrSeries.Values(lngrow) > chrSeries.Values(lngrow - 1) Then If chrSeries.Values(lngrow) > chrSeries.Values(lngrow + 1) Then chrSeries.Points(lngrow).ApplyDataLabels With chrSeries.Points(lngrow).DataLabel .Position = xlLabelPositionCenter .Border.Color = 1 End With End If End If Next End Sub 
+8
source

All Articles