This repository has been archived on 2021-05-17. You can view files and clone it, but cannot push or open issues or pull requests.
scientificComputing/statistics/code/mymedian.m

14 lines
304 B
Matlab

function m = mymedian( x )
% returns the median of the vector x
xs = sort( x );
if ( length( xs ) == 0 )
m = NaN;
elseif ( rem( length( xs ), 2 ) == 0 )
index = length( xs )/2;
m = (xs( index ) + xs( index+1 ))/2;
else
index = (length( xs ) + 1)/2;
m = xs( index );
end
end