medianw

PURPOSE ^

Fast weighted median.

SYNOPSIS ^

function m = medianw( x, w, dim )

DESCRIPTION ^

 Fast weighted median.

 Computes the weighted median of a set of samples.
  http://en.wikipedia.org/wiki/Weighted_median
 "A weighted median of a sample is the 50% weighted percentile."
 For matrices computes median along each column (or dimension dim).
 If all weights are equal to 1 gives identical results to median.

 USAGE
  m = medianw( x, w, [dim] )

 INPUTS
  x      - vector or array of samples
  w      - vector or array of weights
  dim    - dimension along which to compute median

 OUTPUTS
  m      - weighted median value of x

 EXAMPLE - simple toy example
  x=[1 2 3]; w=[1 1 5]; medianw(x,w)

 EXAMPLE - comparison to median
  n=randi(100); m=randi(100);
  x=rand(n,m); w=ones(n,m);
  m1=median(x); m2=medianw(x,w);
  assert(isequal(m1,m2))

 See also median

 Piotr's Computer Vision Matlab Toolbox      Version 3.24
 Copyright 2014 Piotr Dollar.  [pdollar-at-gmail.com]
 Licensed under the Simplified BSD License [see external/bsd.txt]

Generated by m2html © 2003