-1

So my project is to analysis a graph. I want to find algorithm to find the max and min data. I got different value of max in each graph. So i wanna to find the average or the high frequency max value.

PLEASE LOOK AT THIS LINK PICTURE

I have been write to find maximum data. Here my code

Private Function FindMaxDataTableValue(ByRef dt As DataTable) As Integer
    Dim currentValue As Integer, maxValue As Integer
    Dim dv As DataView = dt.DefaultView
    For c As Integer = 0 To dt.Columns.Count - 1
        dv.Sort = dt.Columns(c).ColumnName + " DESC"
        currentValue = CInt(dv(0).Item(c))
        If currentValue > maxValue Then maxValue = currentValue
    Next
    Return maxValue
End Function
  • you could something like: for each graph check every value. Store the first value in variable if the next value if higher then replace it and do same with lower. [Check this](http://stackoverflow.com/questions/2442525/how-to-select-min-and-max-values-of-a-column-in-a-datatable) – Mederic May 03 '17 at 12:39
  • 3
    define `high frequency max value` in your context please – Alex B. May 03 '17 at 13:01
  • @AlexB. how to use the high frequency max value – Abdul Rahim May 03 '17 at 13:48
  • I meant what *is* high frequency max value? How is it defined in terms of your business context. – Alex B. May 03 '17 at 14:10
  • @AlexB. high frequency max value is for example my data is sinusoidal graph so there is different peak value. – Abdul Rahim May 03 '17 at 15:00
  • @AlexB. owh i dont know that the picture i put in the question where not there just now. You could look at that picture – Abdul Rahim May 03 '17 at 15:10
  • Ok so you mean something like a Local Maximum? – Alex B. May 03 '17 at 18:36

1 Answers1

1

If you can use LINQ (.NET 3.5+), then you can just use the Max (and Min, Average) function:

Private Function FindMaxDataTableValue(ByVal dt As DataTable) As Integer
    ' Find the max value for each column
    Dim maximums = (
        From c In dt.Columns.Cast(Of DataColumn)()
        Select dt.AsEnumerable().Max(Function(x) x.Field(Of Integer)(c))
    ).ToList()
    ' Return the highest of the maximums
    Return maximums.Max()
End Function
Mark
  • 8,140
  • 1
  • 14
  • 29