Results 1 to 2 of 2

Thread: This is an chart for one x axis and many y axis

Threaded View

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2005
    Posts
    14

    This is an chart for one x axis and many y axis

    VB Code:
    1. '////////////////////////////////////////////////////////////
    2. '////////// DO NOT DISTRIBUTE WITHOUT PERMISSION
    3. '////////// Wit C. Bushko 8*833 5674
    4. '////////////////////////////////////////////////////////////
    5. Option Explicit
    6. '
    7. Private Const MIN_DISTX = 0.0001
    8. Private Const MIN_DISTY = 0.0001
    9. '
    10. Private Type LineFit
    11.     A As Double
    12.     b As Double
    13.     x1 As Double
    14.     x2 As Double
    15.     q As Double
    16. End Type
    17. '--------------------------------------------------------------------------------
    18. Public Sub CompressData(RawData() As Double, CompData() As Double, _
    19.                 ByVal DistX As Double, ByVal DistY As Double)
    20. '------
    21. ' CompressData finds a multilinear fit to a series of points.
    22. ' Input:
    23. '   RawData(i,j)  - coordinate x (i=0), and coordinate y,(i=1) of the jth point (j=0,1,2,...,n)
    24. '                   of raw data.
    25. '   DistX         - parameter defining the accuracy of x coordinate fit.
    26. '   DistY         - parameter defining the accuracy of y coordinate fit.
    27. ' Output:
    28. '   CompData(i,j) - coordinate x (i=0), and coordinate y,(i=1) of jth point (j=0,1,2,...,n)
    29. '                   of compressed data.
    30. '
    31. '------
    32.     Dim n1 As Long
    33.     Dim n2 As Long
    34.     Dim n, Mx As Long
    35.     Dim A As Double
    36.     Dim b As Double
    37.     Dim Seg() As LineFit
    38.     Dim i As Integer
    39.     Dim y1, y2, ymax, ymin As Double
    40.     Dim NorD As Double
    41. '---
    42.     If DistX < MIN_DISTX Then DistX = MIN_DISTX
    43.     If DistY < MIN_DISTY Then DistX = MIN_DISTY
    44. '
    45.     Mx = UBound(RawData, 2)
    46. '
    47.     n = -1
    48.     n1 = 0
    49.     Do
    50.         LinearFit RawData(), n1, n2, DistX, DistY, A, b, NorD
    51. '
    52.         n = n + 1: ReDim Preserve Seg(n)
    53.         Seg(n).A = A
    54.         Seg(n).b = b
    55.         Seg(n).x1 = RawData(0, n1)
    56.         Seg(n).x2 = RawData(0, n2)
    57.         Seg(n).q = NorD
    58.         If n2 = Mx Then Exit Do
    59.         n1 = n2
    60.     Loop
    61. '-------
    62.     ReDim CompData(1, n + 1)
    63.     CompData(0, 0) = Seg(0).x1
    64.     CompData(1, 0) = Seg(0).A * Seg(0).x1 + Seg(0).b
    65.     For i = 1 To n
    66.         CompData(0, i) = Seg(i).x1
    67.         y1 = Seg(i - 1).A * CompData(0, i) + Seg(i - 1).b + Seg(i - 1).q
    68.         y2 = Seg(i).A * CompData(0, i) + Seg(i).b + Seg(i).q
    69.         If y1 < y2 Then ymax = y1 Else ymax = y2
    70.         y1 = Seg(i - 1).A * CompData(0, i) + Seg(i - 1).b - Seg(i - 1).q
    71.         y2 = Seg(i).A * CompData(0, i) + Seg(i).b - Seg(i).q
    72.         If y1 > y2 Then ymin = y1 Else ymin = y2
    73.         CompData(1, i) = (ymin + ymax) / 2#
    74.     Next
    75.     CompData(0, n + 1) = Seg(n).x2
    76.     CompData(1, n + 1) = Seg(n).A * Seg(n).x2 + Seg(n).b
    77. '---
    78. End Sub
    79. '--------------------------------------------------------------------------------
    80. Private Sub LinearFit(y() As Double, nmin As Long, nmax As Long, _
    81.                 ByVal DistX As Double, ByVal DistY As Double, _
    82.                 A As Double, b As Double, NorD As Double)
    83. '---
    84.     Dim Flg As Boolean
    85.     Dim i, n1, n2, Mx, m, Dn, q As Long
    86.     Dim Sx, Sxx, Sy, Sxy As Double
    87.     Dim MaxD As Double
    88. '---
    89.     Mx = UBound(y, 2)
    90. '
    91.     Sx = y(0, nmin): Sxx = y(0, nmin) * y(0, nmin)
    92.     Sy = y(1, nmin)
    93.     Sxy = y(0, nmin) * y(1, nmin)
    94. '
    95.     nmax = nmin
    96.     Dn = 1
    97.     n1 = nmax + 1
    98.     nmax = nmax + Dn
    99.     n2 = nmax
    100.     q = 1
    101. '-------
    102.     Do
    103.         For i = n1 To n2
    104.             Sx = Sx + q * y(0, i): Sxx = Sxx + q * y(0, i) * y(0, i)
    105.             Sy = Sy + q * y(1, i)
    106.             Sxy = Sxy + q * y(0, i) * y(1, i)
    107.         Next
    108.         m = nmax - nmin + 1
    109.         A = (m * Sxy - Sx * Sy) / (m * Sxx - Sx * Sx)
    110.         b = (Sxx * Sy - Sx * Sxy) / (m * Sxx - Sx * Sx)
    111. '-------
    112.         NorD = Sqr(DistX * DistX * A * A + DistY * DistY)
    113.         MaxD = MaxDistance(y(), nmin, nmax, A, b)
    114. '-------
    115.         If NorD > MaxD Then
    116.             If Flg Then
    117.                 If Dn = 1 Then Exit Sub
    118.                 Dn = Dn / 2
    119.             Else
    120.                 Dn = 2 * Dn
    121.                 Do While nmax + Dn > Mx
    122.                     If Dn = 1 Then Exit Sub
    123.                     Dn = Dn / 2
    124.                 Loop
    125.             End If
    126.             n1 = nmax + 1
    127.             nmax = nmax + Dn
    128.             n2 = nmax
    129.             q = 1
    130.         Else
    131.             Flg = True
    132.             If Dn > 1 Then Dn = Dn / 2
    133.             n2 = nmax
    134.             nmax = nmax - Dn
    135.             n1 = nmax + 1
    136.             q = -1
    137.         End If
    138.     Loop
    139. '---
    140. End Sub
    141. '--------------------------------------------------------------------------------
    142. Private Function MaxDistance(f() As Double, _
    143.                                 n1 As Long, n2 As Long, _
    144.                                 A As Double, b As Double) As Double
    145. '---
    146.     Dim i As Integer
    147.     Dim d As Double
    148. '---
    149.     MaxDistance = 0#
    150.     For i = n1 To n2
    151.         d = Abs(A * f(0, i) + b - f(1, i))
    152.         If d > MaxDistance Then MaxDistance = d
    153.     Next
    154. '---
    155. End Function
    156. '--------------------------------------------------------------------------------


    I am new to vb
    so i am not able understand this code and i have to do the same for one
    x axis and many y axis Can u guide me to code for that and explain me this.

    I am in an urgent please let me know soon
    Last edited by RobDog888; Feb 16th, 2005 at 11:30 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width