function m = mymedian( x )
% returns the median of the vector x
  xs = sort( x );
  if ( length( xs ) == 0 )                 % empty input vector
    m = NaN;
  elseif ( rem( length( xs ), 2 ) == 0 )   % even number of data values
    index = length( xs )/2;
    m = (xs( index ) + xs( index+1 ))/2;   % average the two central elements
  else                                     % odd number of data values
    index = (length( xs ) + 1)/2;          % take the middle element
    m = xs( index );
  end
end
