File Exchange

image thumbnail

weighted median

version 1.0 (1.71 KB) by

Function for calculating the weighted median



View License

For n numbers x_1,...,x_n with positive weights w_1,...,w_n,
(sum of all weights equal to one) the weighted median is defined as
the element x_k, such that:
) w_i <= 1/2
x_i < x_k
) w_i <= 1/2
x_i > x_k

Input: D ... matrix of observed values
W ... matrix of weights, W = ( w_ij )
Output: wMed ... weighted median

Comments and Ratings (7)


Theo (view profile)

Worked like a charm !!!

Song Ming

very useful. And Bart's comments are great too.


Qiao Liyong

Useful routine. It can be optimized, though, by using sumVec=cumsum(wSort) -- it gave me a speed-up of more than 300 in a particular case for which I had about 50000 elements.

Fun Flow

Fun Flow

MATLAB Release
MATLAB 7 (R14)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video