title: Exception in MatlabControl when running MATLAB function outside MATLAB
body: <p>I need help to connect between Java and MATLAB via <a href="http://code.google.com/p/matlabcontrol/" rel="nofollow">MatlabControl</a> .</p>
  
  <p>firstly i wanted to test code in walkthrough but every time i got same exception  :</p>
  
  <p>myfunc.m :</p>
  
  <pre><code>function myfunc()
      disp('hello from MYFUNC')
  end
  </code></pre>
  
  <p>Java:</p>
  
  <pre><code>class ShowImage {
  
   public static void main(String[] args)
          throws MatlabConnectionException, MatlabInvocationException
      {
           // create proxy
           MatlabProxyFactoryOptions options =
              new MatlabProxyFactoryOptions.Builder()
                  .setUsePreviouslyControlledSession(true)
                  .build();
          MatlabProxyFactory factory = new MatlabProxyFactory(options);
          MatlabProxy proxy = factory.getProxy();
  
          // call builtin function
          proxy.eval("disp('hello world')");
  
          // call user-defined function (must be on the path)
          proxy.eval("addpath('E:\\vm')");
          proxy.feval("myfunc");
          proxy.eval("rmpath('E:\\vm)");
  
          // close connection
          proxy.disconnect();
  
  }}
  </code></pre>
  
  <p>and here's exceptions :</p>
  
  <pre><code>Exception in thread "main" matlabcontrol.MatlabConnectionException: Could not launch MATLAB. Command: [matlab, -r, javaaddpath 'C:\Users\walaa\Desktop\matlabcontrol-4.0.0.jar'; matlabcontrol.MatlabClassLoaderHelper.configureClassLoading(); javarmpath 'C:\Users\walaa\Desktop\matlabcontrol-4.0.0.jar'; matlabcontrol.MatlabConnector.connectFromMatlab('PROXY_RECEIVER_42dd44d9-815e-41ad-bec9-e469718b5710', 2100);]
      at matlabcontrol.RemoteMatlabProxyFactory.createProcess(RemoteMatlabProxyFactory.java:305)
      at matlabcontrol.RemoteMatlabProxyFactory.requestProxy(RemoteMatlabProxyFactory.java:116)
      at matlabcontrol.RemoteMatlabProxyFactory.getProxy(RemoteMatlabProxyFactory.java:134)
      at matlabcontrol.MatlabProxyFactory.getProxy(MatlabProxyFactory.java:81)
      at ShowImage.main(ShowImage.java:19)
  Caused by: java.io.IOException: Cannot run program "matlab": CreateProcess error=2, The system cannot find the file specified
      at java.lang.ProcessBuilder.start(Unknown Source)
      at matlabcontrol.RemoteMatlabProxyFactory.createProcess(RemoteMatlabProxyFactory.java:292)
      ... 4 more
  Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified
      at java.lang.ProcessImpl.create(Native Method)
      at java.lang.ProcessImpl.&lt;init&gt;(Unknown Source)
      at java.lang.ProcessImpl.start(Unknown Source)
      ... 6 more
  </code></pre>
  
  <p>I don't know what's the problem, any help will be appreciated!!</p>