function median2, arr ;use instead of median. Median takes the wrong answer ;when you have an even number of elements. n = n_elements(arr) if (n mod 2 eq 1) then mdn=median(arr) if (n mod 2 eq 0) then begin sub1 = arr(sort(arr)) mdn=0.5*(median(arr)+sub1(-1+n/2)) ;integer division here. endif return, mdn end