Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // create the matlab file for executing
- File uOutput = File.createTempFile("matlab-svds-U",".dat");
- File sOutput = File.createTempFile("matlab-svds-S",".dat");
- File vOutput = File.createTempFile("matlab-svds-V",".dat");
- LOG.fine("writing Matlab output to files:\n" +
- " " + uOutput + "\n" +
- " " + sOutput + "\n" +
- " " + vOutput + "\n");
- String commandLine = "matlab -nojvm -nosplash";
- LOG.fine(commandLine);
- Process matlab = Runtime.getRuntime().exec(commandLine);
- // capture the input so we know then Matlab is finished
- BufferedReader br = new BufferedReader(
- new InputStreamReader(matlab.getInputStream()));
- // pipe Matlab the program to execute
- System.out.println(matrix.getAbsolutePath());
- System.out.println(br.readLine());
- PrintWriter pw = new PrintWriter(matlab.getOutputStream());
- pw.println(
- "Z = load('" + matrix.getAbsolutePath() + "','-ascii');\n" +
- "A = spconvert(Z);\n" +
- "% Remove the raw data file to save space\n" +
- "clear Z;\n" +
- "[U, S, V] = svds(A, " + dimensions + " );\n" +
- "save " + uOutput.getAbsolutePath() + " U -ASCII\n" +
- "save " + sOutput.getAbsolutePath() + " S -ASCII\n" +
- "save " + vOutput.getAbsolutePath() + " V -ASCII\n" +
- "fprintf('Matlab Finished\n');");
- System.out.println("uOutput path = "+uOutput.getAbsolutePath());
- pw.close();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement