private String toMatrixString(int[][] counts, int[] clusterTotals,
			Instances inst) throws Exception {
		StringBuffer ms = new StringBuffer();

		int maxval = 0;
		for (int i = 0; i < m_numClusters; i++) {
			for (int j = 0; j < counts[i].length; j++) {
				if (counts[i][j] > maxval) {
					maxval = counts[i][j];
				}
			}
		}

		int Cwidth = 1 + Math.max((int) (Math.log(maxval) / Math.log(10)),
				(int) (Math.log(m_numClusters) / Math.log(10)));

		ms.append("\n");

		for (int i = 0; i < m_numClusters; i++) {
			if (clusterTotals[i] > 0) {
				ms.append(" ").append(
						Utils.doubleToString((double) i, Cwidth, 0));
			}
		}
		ms.append("  <-- assigned to cluster\n");

		for (int i = 0; i < counts[0].length; i++) {

			for (int j = 0; j < m_numClusters; j++) {
				if (clusterTotals[j] > 0) {
					ms.append(" ").append(
							Utils.doubleToString((double) counts[j][i], Cwidth,
									0));
				}
			}
			ms.append(" | ").append(inst.classAttribute().value(i))
					.append("\n");
		}

		return ms.toString();
	}