
January 14th, 2011, 09:46 PM
#1
Median of array values
Hi All,
If i have 8bit values saved in an array of 127 bytes, how would i calculate the Median of this array. Median of a set of values would be the central value of the set when its values are arranged in ascending order.
Any help would be great.
naim1

January 14th, 2011, 10:44 PM
#2
Re: Median of array values

January 14th, 2011, 11:41 PM
#3
Re: Median of array values
Thanks Chris F for the link.
Is it possible to do it using plain ANSI C ?

January 15th, 2011, 12:36 AM
#4
Re: Median of array values
I've never used this before, but here is a C library function.
http://www.cplusplus.com/reference/c...cstdlib/qsort/

January 15th, 2011, 01:10 AM
#5
Re: Median of array values
Thanks again Chris F.
any idea where can i get code for qsort()?
Another point is that the values are not constant in the array, instead the array is being filled up constatly by newer values which are bering received from the serial port. Is it possible to do the sorting operation of every new incoming value dynamically, something like serialarithmatic?

January 15th, 2011, 08:49 AM
#6
Re: Median of array values
Originally Posted by naim1
Thanks again Chris F.
any idea where can i get code for qsort()?
The qsort() is a standard library function. Any code for it would come with your compiler (if your compiler offers source code to the library routines).
Regards,
Paul McKenzie

January 15th, 2011, 01:17 PM
#7
Re: Median of array values
If you wanted a better average case performance than sorting and then picking the middle, you could use the nth element algorithm of picking a pivot, partitioning as in quick sort, and then only performing the recursion on the partition that contains the middle element.
Originally Posted by naim1
Another point is that the values are not constant in the array, instead the array is being filled up constatly by newer values which are bering received from the serial port. Is it possible to do the sorting operation of every new incoming value dynamically, something like serialarithmatic?
As in the new values replace existing ones in the array?
Posting Permissions
 You may not post new threads
 You may not post replies
 You may not post attachments
 You may not edit your posts

Forum Rules

Click Here to Expand Forum to Full Width
This a Codeguru.com survey!
