私は自分のプロジェクトでmatlabを使用しています。私はjavaでmatlabの結果を取得したいと思います。ちょうど結果が欲しい。 私はjavaのmatlabでファイルの結果を取得したいと思います。 私はこのコードを使用しますが、matlab windoの結果を私に与えて、Javaでのみ結果を取得したいだけです。 これはコードですjavaでmatlabの結果を取得
public class matlab {
private static File myMATLABScript;
//private static File myMATLABScript;
public static String runScript(File scriptName) {
String output = "" ;
String error = "";
try {
//String commandToRun = "matlab -r myMATLABScript -nodisplay < " + scriptName;
String commandToRun = "matlab -nosplash -r myMATLABScript -nodisplay -nodesktop < " + scriptName;
System.out.println(commandToRun);
Process p = Runtime.getRuntime().exec(commandToRun);
String s;
BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream()));
// read the output from the command
System.out.println("\nHere is the standard output of the command:\n");
while ((s = stdInput.readLine()) != null) {
output = s + "\n";
System.out.println(s);
//System.out.println("what is the problem");
}
// read any errors from the attempted command
//System.out.println("\nHere is the standard error of the command (if any):\n);
while ((s = stdError.readLine()) != null) {
error = s + "\n";
System.out.println(s);
}
} catch (Exception e) {
System.out.println("exception happened - here’s what I know: ");
e.printStackTrace();
System.exit(-1);
}
return output + error;
}
public static void main(String[] args) throws IOException{
matlab m = new matlab();
matlab.runScript(myMATLABScript);
}
}
私を助けてくれますか?
これまでに既にこれを尋ねたようです:http://stackoverflow.com/questions/794997/how-do-i-get-results-from-matlab-in-javaこの追加のコードを使用して他の質問を更新し、この質問を削除する必要があります。 – gnovice