Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2013
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. // create the matlab file for executing
  2. File uOutput = File.createTempFile("matlab-svds-U",".dat");
  3. File sOutput = File.createTempFile("matlab-svds-S",".dat");
  4. File vOutput = File.createTempFile("matlab-svds-V",".dat");
  5. LOG.fine("writing Matlab output to files:\n" +
  6. " " + uOutput + "\n" +
  7. " " + sOutput + "\n" +
  8. " " + vOutput + "\n");
  9.  
  10.  
  11. String commandLine = "matlab -nojvm -nosplash";
  12. LOG.fine(commandLine);
  13. Process matlab = Runtime.getRuntime().exec(commandLine);
  14.  
  15. // capture the input so we know then Matlab is finished
  16. BufferedReader br = new BufferedReader(
  17. new InputStreamReader(matlab.getInputStream()));
  18.  
  19. // pipe Matlab the program to execute
  20. System.out.println(matrix.getAbsolutePath());
  21. System.out.println(br.readLine());
  22. PrintWriter pw = new PrintWriter(matlab.getOutputStream());
  23. pw.println(
  24. "Z = load('" + matrix.getAbsolutePath() + "','-ascii');\n" +
  25. "A = spconvert(Z);\n" +
  26. "% Remove the raw data file to save space\n" +
  27. "clear Z;\n" +
  28. "[U, S, V] = svds(A, " + dimensions + " );\n" +
  29. "save " + uOutput.getAbsolutePath() + " U -ASCII\n" +
  30. "save " + sOutput.getAbsolutePath() + " S -ASCII\n" +
  31. "save " + vOutput.getAbsolutePath() + " V -ASCII\n" +
  32. "fprintf('Matlab Finished\n');");
  33.  
  34. System.out.println("uOutput path = "+uOutput.getAbsolutePath());
  35.  
  36. pw.close();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement