public static synchronized Matlab getInstance() throws Exception { if (matlab == null) { matlab = getInstance(findMatlab()); } return matlab; }
public static synchronized Matlab getInstance(String pathToMatlab) throws Exception { if (matlab == null) { matlab = new Matlab(pathToMatlab); } return matlab; }
public String execute(String command) throws Exception { sendToMatlab(command); return getFromMatlab(); }
public void actionPerformed(ActionEvent e) { try { Matlab.getInstance().plot(matrix.getMatrix()); } catch (Exception e1) { e1.printStackTrace(); } } }
public void actionPerformed(ActionEvent e) { try { Matlab.getInstance().bar(matrix.getMatrix()); } catch (Exception e1) { e1.printStackTrace(); } } }
public void actionPerformed(ActionEvent e) { try { Matlab.getInstance().plotmatrix(matrix.getMatrix()); } catch (Exception e1) { e1.printStackTrace(); } } }
public void actionPerformed(ActionEvent e) { try { Matlab.getInstance().hist(matrix.getMatrix()); } catch (Exception e1) { e1.printStackTrace(); } } }
public void actionPerformed(ActionEvent e) { try { Matlab.getInstance().barh(matrix.getMatrix()); } catch (Exception e1) { e1.printStackTrace(); } } }
public void actionPerformed(ActionEvent e) { try { Matlab.getInstance().imagesc(matrix.getMatrix()); } catch (Exception e1) { e1.printStackTrace(); } } }
public void actionPerformed(ActionEvent e) { try { Matlab.getInstance().pie(matrix.getMatrix()); } catch (Exception e1) { e1.printStackTrace(); } } }
public void actionPerformed(ActionEvent e) { try { Matlab.getInstance().pie3(matrix.getMatrix()); } catch (Exception e1) { e1.printStackTrace(); } } }
public void actionPerformed(ActionEvent e) { try { Matlab.getInstance().surf(matrix.getMatrix()); } catch (Exception e1) { e1.printStackTrace(); } } }
public void actionPerformed(ActionEvent e) { try { Matlab.getInstance().stem(matrix.getMatrix()); } catch (Exception e1) { e1.printStackTrace(); } } }
if (Matlab.isAvailable()) { MatlabPanel matlabPanel = new MatlabPanel(m); tabbedPane.add("Matlab", matlabPanel);
public double getDouble(String label) throws Exception { Matrix m = getMatrix(label); VerifyUtil.verifySingleValue(m); return m.doubleValue(); }
public Matrix getMatrix(String label) throws Exception { try { String rawRows = execute("fprintf(1,'%d\\n',size(" + label + ",1));"); int rows = Integer.parseInt(rawRows.trim()); String rawCols = execute("fprintf(1,'%d\\n',size(" + label + ",2));"); int cols = Integer.parseInt(rawCols.trim()); String rawText = execute("fprintf(1,'%55.55f\\n'," + label + ")"); String[] rawValues = rawText.split("\n"); Matrix matrix = Matrix.Factory.zeros(rows, cols); int i = 0; for (int c = 0; c < cols; c++) { for (int r = 0; r < rows; r++) { matrix.setAsDouble(Double.parseDouble(rawValues[i++]), r, c); } } return matrix; } catch (Exception e) { e.printStackTrace(); return null; } }
public static boolean isAvailable() { return findMatlab() != null; }
private Matlab(String pathToMatlab) throws Exception { matlabProcess = Runtime.getRuntime().exec(pathToMatlab + " " + MATLABPARAMETERS); output = new BufferedWriter(new OutputStreamWriter(matlabProcess.getOutputStream())); input = new BufferedReader(new InputStreamReader(matlabProcess.getInputStream())); error = new BufferedReader(new InputStreamReader(matlabProcess.getErrorStream())); String startMessage = getFromMatlab(); if (startMessage != null && startMessage.length() > 0) { running = true; return; } throw new Exception("could not start Matlab"); }
public void actionPerformed(ActionEvent e) { try { Matlab.getInstance().plot(matrix.getMatrix().selectColumns(Ret.NEW, 0), matrix.getMatrix().selectColumns(Ret.NEW, 1)); } catch (Exception e1) { e1.printStackTrace(); } } }