function rmed = r8vec_median ( n, r ) %% R8VEC_MEDIAN computes the median of an R8VEC. % % Modified: % % 20 March 2007 % % Author: % % Alan Genz % % MATLAB version by John Burkardt % % Parameters: % % Input, integer N, the dimension of the array. % % Input, real R(N), the array to be examined. % % Output, real RMED(3). RMED(1) contains the median, % RMED(2) and RMED(3) specify the confidence interval. % for j = 1 : n kmax = j; for k = j + 1 : n if ( r(kmax) < r(k) ) kmax = k; end end rmax = r(kmax); r(kmax) = r(j); r(j) = rmax; end nd = floor ( n / 2 ); if ( mod ( n, 2 ) == 0 ) rmed(1) = ( r(nd) + r(nd+1) ) / 2.0; else rmed(1) = r(nd+1); end nconf = max ( 1, floor ( ( 2 * n ) / 5 ) - 2 ); rmed(2) = r(n-nconf+1); rmed(3) = r(nconf);