简体   繁体   中英

How to execute a matlab file on the background through Java?

I have a Java program that makes some changes to a matlab file that reads and executes a function. Is there a way to invoke and run this read.m file through the Java program without having to open Matlab? I tried searching matlabcontrol documentation but I didnt find anything relevant. I would appreciate it if anyone could guide me through.

Thank you in advance.

public static void tomatlab() throws MatlabConnectionException, MatlabInvocationException {


        MatlabProxyFactoryOptions options =
            new MatlabProxyFactoryOptions.Builder()
                .setUsePreviouslyControlledSession(true)
                .build();
        MatlabProxyFactory factory = new MatlabProxyFactory(options);
        MatlabProxy proxy = factory.getProxy();


        proxy.eval("addpath('C:\\path_to_m_file)");
        proxy.feval("read");
        proxy.eval("rmpath('C:\\path_to_m_file')");

        // close connection
        proxy.disconnect();

    }

You need a runtime environment vor M-code. Possibilities I see are:

  • use Matlab control which opens matlab
  • use builder ja which deploys a jar including the necessary parts of the runtime
  • if your M-code is compatible to octave, you can use the c++ interface of octave to create a dll, which can be used independent from Matlab .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM