;+ ; NAME: ; TRIMMEAN ; PURPOSE: ; Find the value that best minimize the deviation to the array ;EXPLANATION: ; xxx ; ; CALLING SEQUENCE: ; RESULT = TRIMMEAN( ARRAY ) ; ; INPUTS: ; ARRAY : An array of values for which the estimate is sought ; ; OUTPUTS: ; RESULT : The value that best minimize the deviation to the elements of ; the input array. ; ; MODIFICATION HISTORY: ; Original Version written in October 2013, B. Carry (IMCCE) ;- function TRIMMEAN, ARRAY N = n_elements( array ) sorted = array(sort(array)) nIter = N/2. mu =fltarr(nIter) var=fltarr(nIter) nel=intarr(nIter) nel(0) = 1 mu(0) = median(sorted) var(0) = total( (sorted-mu(0))^2. ) / N print, 0, 0.,0., nel(0), mu(0), var(0) for i=1, nIter-1 do begin iBeg = nIter-i iEnd = N - iBeg mu(i) = mean( sorted(iBeg:iEnd) ) nel(i) = n_elements(sorted(iBeg:iEnd)) var(i) = total( (sorted-mu(i))^2. ) / N print, i, iBeg, iEnd, nel(i), mu(i), var(i) endfor ; window, 0 ; h=histogram(sorted,loc=xx, bins=0.02) ; plot, xx,h,psym=10 ; ; window, 1 ; plot, mu,/ynoz ; ; ; window, 2 ; plot, var, /ynoz varMin = min( var, pMin ) muMin = mu(pMin) print, pMin, muMin, varMin return, [muMin, varMin] end