title: using matlabcontrol API to call to call matlab function from Java within Netbeans
body: <p>I have been trying to edit the the following matlabcontrol code but still there is an error when I run it. Please friends help me out!</p>
  
  <pre><code>package matcontro;
  
  import matlabcontrol.*;
  
  public class HelloWorld
  
   {
  
        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('C:\\ Users\\HASENDE\\My Documents\\MATLAB')");
           proxy.feval("myfunc");
           proxy.eval("rmpath('C:\\ Users\\HASENDE\\My Documents\\MATLAB')");
  
           // close connection
           proxy.disconnect();
       }
   }
  </code></pre>
  
  <p>The error that I get is below;</p>
  
  <p>run:</p>
  
  <blockquote>
    <p>Exception in thread "main" matlabcontrol.MatlabConnectionException:
    Could not launch MATLAB. Command: [matlab, -r, javaaddpath
    'C:\Users\HASENDE\Documents\NetBeansProjects\Java Classpath
    Libraries\matlabcontrol-4.0.0.jar';
    matlabcontrol.MatlabClassLoaderHelper.configureClassLoading();
    javarmpath 'C:\Users\HASENDE\Documents\NetBeansProjects\Java Classpath
    Libraries\matlabcontrol-4.0.0.jar';
    matlabcontrol.MatlabConnector.connectFromMatlab('PROXY_RECEIVER_01caa56d-9ed7-4e39-a45b-345051024d49',
    2100);]</p>
    
    <p>at
    matlabcontrol.RemoteMatlabProxyFactory.createProcess(RemoteMatlabProxyFactory.java:305)
       at
    matlabcontrol.RemoteMatlabProxyFactory.requestProxy(RemoteMatlabProxyFactory.java:116)</p>
    
    <p>at
    matlabcontrol.RemoteMatlabProxyFactory.getProxy(RemoteMatlabProxyFactory.java:134)</p>
  
  <pre><code>    at matlabcontrol.MatlabProxyFactory.getProxy(MatlabProxyFactory.java:81)
  
      at matcontro.HelloWorld.main(HelloWorld.java:21)
  </code></pre>
    
    <p>Caused by: java.io.IOException: Cannot run program "matlab": CreateProcess error=2, The system cannot find the file specified   at
    java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)   at
    matlabcontrol.RemoteMatlabProxyFactory.createProcess(RemoteMatlabProxyFactory.java:292)
      ... 4 more</p>
    
    <p>Caused by: java.io.IOException: CreateProcess error=2, The system
    cannot find the file specified</p>
  
  <pre><code>    at java.lang.ProcessImpl.create(Native Method)
  
      at java.lang.ProcessImpl.&lt;init&gt;(ProcessImpl.java:188)
  
      at java.lang.ProcessImpl.start(ProcessImpl.java:132)
  
      at java.lang.ProcessBuilder.start(ProcessBuilder.java:1021)   ... 5 more
  </code></pre>
    
    <p>Java Result: 1</p>
  </blockquote>
  
  <p>BUILD SUCCESSFUL (total time: 4 seconds)</p>