View License

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

» Watch video

Highlights from
weighted median

Join the 15-year community celebration.

Play games and win prizes!

» Learn more

4.0 | 6 ratings Rate this file 11 Downloads (last 30 days) File Size: 1.71 KB File ID: #23077 Version: 1.0

weighted median



Function for calculating the weighted median

| Watch this File

File Information

 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


This file inspired Weighted Median (From Data & Sds) & Its Standard Deviation.

MATLAB release MATLAB 7 (R14)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (7)
03 Apr 2015 Theo

Theo (view profile)

Worked like a charm !!!

01 Aug 2014 Song Ming

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

03 Oct 2012 petrichor  
20 Oct 2011 Qiao Liyong  
16 Sep 2010 Bart Vorselaars

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.

Comment only
30 Mar 2009 Fun Flow  
30 Mar 2009 Fun Flow  

Contact us