Here you can find the source of median(float[] vector)
Parameter | Description |
---|---|
vector | a parameter |
public static float median(float[] vector)
//package com.java2s; /******************************************************************************* * Caleydo - Visualization for Molecular Biology - http://caleydo.org * Copyright (c) The Caleydo Team. All rights reserved. * Licensed under the new BSD license, available at http://caleydo.org/license ******************************************************************************/ import java.util.Arrays; public class Main { /**// w ww . j a v a 2 s . c o m * Calculates the median for a given vector (float array) * * @param vector * @return median */ public static float median(float[] vector) { float median = 0; float[] temp = new float[vector.length]; for (int i = 0; i < temp.length; i++) { if (Float.isNaN(vector[i])) temp[i] = 0; else temp[i] = vector[i]; } Arrays.sort(temp); if ((temp.length % 2) == 0) median = (temp[(int) Math.floor(temp.length / 2)] + temp[(int) Math.floor((temp.length + 1) / 2)]) / 2; else median = temp[(int) Math.floor((temp.length + 1) / 2)]; return median; } }