0

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();

    }
user3211165
  • 225
  • 1
  • 3
  • 14

1 Answers1

0

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 .
Daniel
  • 36,610
  • 3
  • 36
  • 69
  • Thank you for the reply. The third option is impossible in my case. Is there a way to avoid opening matlab TO execute the .m file through Matlab control? - With builder ja I will have to convert every time I run the program the .m file to jar to execute it, but is the conversion efficient? – user3211165 Jun 20 '14 at 10:51
  • You have to run Matlab, otherwise there is no interpreter for M-code. The builder ja makes the code slower, because it is not using the native libraries, but there is nearly no startup time. – Daniel Jun 20 '14 at 15:16
  • Which is the class of matlabcontrol that executes the .m files? Because I cant find anything relevant. – user3211165 Jun 23 '14 at 14:03