*/
public String toTitleString(DoubleMatrix2D matrix, String[] rowNames, String[] columnNames, String rowAxisName, String columnAxisName, String title, hep.aida.bin.BinFunction1D[] aggr) {
if (matrix.size()==0) return "Empty matrix";
if (aggr==null || aggr.length==0) return toTitleString(matrix,rowNames,columnNames,rowAxisName,columnAxisName,title);
DoubleMatrix2D rowStats = matrix.like(matrix.rows(), aggr.length); // hold row aggregations
DoubleMatrix2D colStats = matrix.like(aggr.length, matrix.columns()); // hold column aggregations
cern.colt.matrix.doublealgo.Statistic.aggregate(matrix, aggr, colStats); // aggregate an entire column at a time
cern.colt.matrix.doublealgo.Statistic.aggregate(matrix.viewDice(), aggr, rowStats.viewDice()); // aggregate an entire row at a time
// turn into strings
// tmp holds "matrix" plus "colStats" below (needed so that numbers in a columns can be decimal point aligned)
DoubleMatrix2D tmp = matrix.like(matrix.rows()+aggr.length, matrix.columns());
tmp.viewPart(0,0,matrix.rows(),matrix.columns()).assign(matrix);
tmp.viewPart(matrix.rows(),0,aggr.length,matrix.columns()).assign(colStats);
colStats = null;
String[][] s1 = format(tmp); align(s1); tmp = null;
String[][] s2 = format(rowStats); align(s2); rowStats = null;