How to extract and plot only minimal and maximal peaks of an array , -graph analysis- With Matlab or excel

后端 未结 3 1194
礼貌的吻别
礼貌的吻别 2020-12-11 18:16

I\'m doing video analysis.
The end result array I get is something like:

signal =

    Columns 1 through 7

       73960       73960       73960       73         


        
3条回答
  •  旧巷少年郎
    2020-12-11 18:39

    This VBA

    • Reads the data from column A and B into a variant arrays
    • Find the local minima and maxima and extracts that to second array
    • Creates a brand new chart of the minima/maximia (see image)

    enter image description here

         Sub NewGraph()
        Dim X
        Dim Y
        Dim lngRow As Long
        Dim lngCnt As Long
        Dim Chr As ChartObject
    
        X = Range([a1], Cells(Rows.Count, "b").End(xlUp))
        Y = Application.Transpose(X)
    
        For lngRow = 2 To UBound(X, 1) - 1
            If X(lngRow, 2) > X(lngRow - 1, 2) Then
                If X(lngRow, 2) > X(lngRow + 1, 2) Then
                    lngCnt = lngCnt + 1
                    Y(1, lngCnt) = X(lngRow, 1)
                    Y(2, lngCnt) = X(lngRow, 2)
                End If
            Else
                If X(lngRow, 2) < X(lngRow + 1, 2) Then
                    lngCnt = lngCnt + 1
                    Y(1, lngCnt) = X(lngRow, 1)
                    Y(2, lngCnt) = X(lngRow, 2)
                End If
            End If
        Next lngRow
    
        ReDim Preserve Y(1 To 2, 1 To lngCnt)
    
        Set Chr = ActiveSheet.ChartObjects.Add(250, 175, 275, 200)
        With Chr.Chart
    
            With .SeriesCollection.NewSeries
                .XValues = Application.Index(Application.Transpose(Y), 0, 1)
                .Values = Application.Index(Application.Transpose(Y), 0, 2)
            End With
            .ChartType = xlXYScatter
        End With
    
    End Sub
    

提交回复
热议问题