title: How to call Matlab functions from Java using matlabcontrol without starting new session every time?
body: <p>I am using matlabcontrol to call Matlab functions from Java</p>
  
  <p>My code works well, but it opens new Matlab session whenever I run my code in Java.
  I edited according to Javadoc, but I guess I missed something.</p>
  
  <p>I also tried this with/without 'proxy.disconnect()', but it still opens new Matlab session.
  Any hint will be very helpful. I am stuck..</p>
  
  <p>below is my Java code</p>
  
  <pre><code>import matlabcontrol.MatlabConnectionException;
  import matlabcontrol.MatlabInvocationException;
  import matlabcontrol.MatlabProxy;
  import matlabcontrol.MatlabProxyFactory;
  import matlabcontrol.MatlabProxyFactoryOptions;
  
  public class callSaliencymap {
  
  /**
   * @param args
   */
  public static void main(String[] args) throws MatlabConnectionException, MatlabInvocationException
  {
      //Create a proxy, which we will use to control MATLAB
      MatlabProxyFactory factory = new MatlabProxyFactory();
      MatlabProxy proxy = factory.getProxy();
  
      MatlabProxyFactoryOptions options = new MatlabProxyFactoryOptions.Builder()
      .setUsePreviouslyControlledSession(true)
      .setHidden(true)
      .build();
  
      factory = new MatlabProxyFactory(options);
  
  
  
  
      //Create proxy factory
  
  
      //test the saliencymap
      Object[] saliencylocation = proxy.returningFeval("runActivation",1,"tank.bmp",1);
      System.out.println(saliencylocation[0]);
  
      //Disconnect the proxy from MATLAB
      //proxy.disconnect();
  }
  </code></pre>