List of usage examples for weka.core.matrix Matrix write
public void write(Writer w) throws Exception
From source file:org.mitre.ccv.CompleteCompositionVectorMain.java
License:Open Source License
/** * Write out the distance matrix to the given BufferedWriter. * // ww w. j av a2 s .co m * @param dm the DistanceMatrix. * @param bw the BufferedWriter to write distance to. * */ public void writeDistanceMatrix(DistanceMatrix dm, BufferedWriter bw) throws IOException { double[][] mVals = dm.getClonedDistances(); Matrix m = new Matrix(mVals); /** was when this was writeSimilarityMatrix if (distCalc == 1 || distCalc == 3) { m = m.times(-1.0); } else if (distCalc == 2 || distCalc == 4) { Matrix o = new Matrix(m.getRowDimension(), m.getColumnDimension(), 1.0); m = o.minus(m); } */ try { m.write(bw); // Write the matrix to the file. /** bw.write(this.distCalc.toString() + "\n"); for (int i = 0; i < m.getRowDimension(); i++) { for (int j = 0; j < m.getColumnDimension(); j++) { String s = String.format("%03d\t%03d\t%f\n", i + 1, j + 1, m.get(i, j)); bw.write(s); } } */ bw.close(); } catch (Exception ex) { throw new IOException(ex.getMessage()); } }