public static RealMatrixExt median(RealMatrixExt[] matrices) {
        int numMat = matrices.length;
        double[] aggregator = new double[numMat];

        int nRows = matrices[0].getRowDimension();
        int nCols = matrices[0].getColumnDimension();
        // TODO: check if #rows and #cols is equal in all matrices!

        double[][] result = new double[nRows][nCols];

        boolean center = !(numMat % 2 == 0);
        int ctridx;
        if (center)
            ctridx = (numMat - 1) / 2;
        else
            ctridx = (numMat / 2) - 1;

        for (int r = 0; r < nRows; r++) {
            for (int c = 0; c < nCols; c++) {
                for (int m = 0; m < numMat; m++) {
                    aggregator[m] = matrices[m].getEntry(r, c); // [r][c];
                }
                Arrays.sort(aggregator);
                if (center)
                    result[r][c] = aggregator[ctridx];
                else
                    result[r][c] = (aggregator[ctridx] + aggregator[ctridx + 1]) / 2;
            }
        }

        RealMatrixExt resultM = new RealMatrixExt(result);
        resultM.setType(matrices[0].getType()); // set type id to 1st matrix in
        // array

        return resultM;

    }