1

I'm using the matlabcontrol package in Java to connect to Matlab r2015a and start a selected script. This is all working great, but every time I run the script, Matlab opens a command window with the output. This output is already returned in Eclipse, so it's redundant.

I'm creating a session with Matlab the following way:

public interface IMatLab {

MatlabProxyFactoryOptions options = new MatlabProxyFactoryOptions.Builder()
        .setUsePreviouslyControlledSession(true).setHidden(true)
        .setMatlabLocation(null).build();
MatlabProxyFactory factory = new MatlabProxyFactory(options);

public static String runScript(String pathFunc, int param1, int param2)
        throws MatlabConnectionException, MatlabInvocationException {

    MatlabProxy proxy = factory.getProxy();

    // locating MatLab files
    proxy.setVariable("path", pathFunction);
    proxy.eval("addpath(path)");

    // calling add function in MatLab code
    Object[] obj = proxy.returningFeval("add", 1, param1, param2);
    String outputScript = toString(obj[0]);

    return outputScript;
}

Is there any way to hide the command window when calling Matlab? With the 'setHidden' to false, it starts the full Matlab session, instead of just the command window.

I prefer to do this in java itself. If that's not an option, changing config in Matlab is also fine.

Camelaria
  • 284
  • 6
  • 23

1 Answers1

0

As far as I know, there is no way to do this without using native code. The reason is:

  1. Since sending commands by another program is not officially supported by Matlab, there is no reason for them to implement a Matlab without any form of I/O capabilities.

  2. The Matlab program is not part of the JVM your java code is running on, so you won't find a pure java approach to change it (hide it or ...).

So I guess the only way is using native OS API (using JNA or ...). The way to do it, and whether it is possible or not, depends on your Operating System (for doing this in Windows see this question).

By the way, I think you should be careful about doing it, the matlabcontrol library is not perfect, sometimes you loose your connection with the Matlab and a new Matlab is opened. If the user can't see the Matlab window, you may end up having a lot of Matlab processes running, without seeing any of them.

Community
  • 1
  • 1
Hassan
  • 396
  • 5
  • 12