Results 1 to 4 of 4

Thread: [RESOLVED] Max Min of x number array elements past

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2010
    Posts
    1,246

    Resolved [RESOLVED] Max Min of x number array elements past

    Greetings.

    I'm trying to tackle a need to get the Max and Min value of the last x elements of an array as quickly as possible.

    I can do this without problem, simply checking the values of the last x elements and seeing if it is the highest or lowest value.

    However, after I do this and get the results, I need to then go to the next element in the array and start the whole process all over again. This just seems like a whole lot of wasted cpu cycles.

    For example:

    Suppose you have an array of type Single values from 1 to 100.

    fValues(1 to 100)

    Suppose I want to get the Max and Min values of 6 elements at a time, starting from fValues(1) to fValues(6), then fValues(2) to fValues(7), then fValues(3) to fValues(8)... all the way to fValues(95) to fValues(100).

    In other words, after each calculation, I drop the oldest (6 elements ago) and add the next element of the array to the calculation.

    Is there a faster way to do this other than to do a Loop on every 6 elements? It's important as the results will be displayed graphically as a line and redraw would be an issue if there was too long a wait.

    Any ideas, tips, etc?

    Thank you.

  2. #2
    Frenzied Member
    Join Date
    Nov 2010
    Posts
    1,470

    Re: Max Min of x number array elements past

    it would be better to do the testing from the last element up 6

    you could try testing the newest element (last) against the min or max values as long as the value is not the 1st element value ie the (last-6 one) as this element has fallen out of the test group

    so for a six element group when a new element is added you only need to recalculate if the seventh back element is either the max or min... this approach will reduce the number of itterations required!

    hope that helps (sounds more complex than it is )

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2010
    Posts
    1,246

    Re: Max Min of x number array elements past

    Yes, I could see how what would speed it up some.

    As long as the array element (back x + 1) does not equal my Max or Min value, there is no reason to run the loop again.

    Thanks. Good suggestion.

  4. #4
    Frenzied Member
    Join Date
    Nov 2010
    Posts
    1,470

    Re: Max Min of x number array elements past

    do not forget to rate the posts and close when you are done using the tools at the top of the threads

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