Note that there are some explanatory texts on larger screens.

plurals
  1. POretrieve matlab result in java
    text
    copied!<p>I use matlab in my project and I want to retrieve the result of matlab in java. Just I want the result. I want to retrive result of file that I make it in matlab in the java. I use this code but it give me the result in matlab windo and I want only to retrive the result in java only. this is the code</p> <pre><code>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 &lt; " + scriptName; String commandToRun = "matlab -nosplash -r myMATLABScript -nodisplay -nodesktop &lt; " + 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); } } </code></pre> <p>could you please help me?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload