Java Median getmedian(double[] vals, int nvalindex)

Here you can find the source of getmedian(double[] vals, int nvalindex)

Description

Returns the median value in vals in indicies between 0 and nvalindex-1

License

Open Source License

Declaration

public static double getmedian(double[] vals, int nvalindex) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.*;

public class Main {
    /**/*  www  . j  a va2  s . c  o m*/
     * Returns the median value in vals in indicies between 0 and nvalindex-1
     */
    public static double getmedian(double[] vals, int nvalindex) {
        double dmedian;
        Arrays.sort(vals, 0, nvalindex);
        if (nvalindex % 2 == 0) {
            dmedian = (vals[nvalindex / 2 - 1] + vals[nvalindex / 2]) / 2;
        } else {
            dmedian = vals[nvalindex / 2];
        }

        return dmedian;
    }
}

Related

  1. calcMedian(final double[] values)
  2. calculateMedianOfArrayListInteger(List integerList)
  3. getMedian(double array[])
  4. getMedian(double[] a)
  5. getMedian(int[] array)
  6. getMedianValue(ArrayList values)
  7. median(ArrayList v)
  8. median(ArrayList values)