Monday, 29 July 2013

Calling Matlab function from Java

 Download matlabcontrol-4.1.0.jar library from https://code.google.com/p/matlabcontrol/

then try below code



import matlabcontrol.*;

import matlabcontrol.MatlabProxyFactory;

import matlabcontrol.MatlabProxyFactoryOptions;



/**

 *

 * @author RajBharath

 */

public class MatlabCommunication{



    /**

     * @param args the command line arguments

     */

    public static void main(String[] args)  throws Exception

    {

         // create proxy

        MatlabProxyFactoryOptions options = new MatlabProxyFactoryOptions.Builder()

             .setUsePreviouslyControlledSession(true)

             .build();

        MatlabProxyFactory factory = new MatlabProxyFactory(options);

        MatlabProxy proxy = factory.getProxy();



        proxy.eval("disp('hello world')");



        // call user-defined function (must be on the path)

       



        // close connection

        proxy.disconnect();



    }



}



Kindly Bookmark and Share it:

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...