0

I am trying to call some of the functions of MATLAB via Java.

What I have on my local machine is MATLAB Runtime(64 bit) and Java 8 64 bit.

Following piece of code gives an error.

Code

//Start MATLAB asynchronously
Future<MatlabEngine> eng = MatlabEngine.startMatlabAsync();

// Get engine instance from the future result
MatlabEngine ml = eng.get();

Exception

com.mathworks.engine.EngineException: Unable to launch MATLAB or connect a shared MATLAB session.
    at com.mathworks.engine.FutureMatlab.get(FutureMatlab.java:54)
    at com.mathworks.engine.FutureMatlab.get(FutureMatlab.java:16)
    at com.poc.EngineConsoleDemo.main(EngineConsoleDemo.java:26)

Please correct me if I'm wrong, but as far as my understanding goes, having a full fledged MATLAB is not required for this to run and this should run even if there's only a MATLAB Runtime installed.

Then, if my understanding is right - why do I get this exception ?

Dev-iL
  • 23,742
  • 7
  • 57
  • 99
Abhishek Singh
  • 10,243
  • 22
  • 74
  • 108
  • Why are you using the asynchronous launch if you're immediately trying to get the result? You can just call `MatlabEngine.startMatlab()` and avoid using a future. See [this article](https://uk.mathworks.com/help/matlab/matlab_external/start-matlab-session-from-java.html) – Michael May 29 '18 at 13:09
  • Doesn't work either way. – Abhishek Singh May 29 '18 at 13:14
  • I have a feeling, based on personal experience and [this documentation article](https://www.mathworks.com/products/compiler/matlab-runtime.html) that the MATLAB Runtime is only meant for running applications compiled in MATLAB itself, and cannot be used to execute arbitrary code, whether it is through java or otherwise. See also [this article on "Java Package Integration"](https://www.mathworks.com/help/compiler_sdk/java_packages.html). – Dev-iL May 29 '18 at 13:24
  • But should this cause problem in MATLAB engine start ? – Abhishek Singh May 29 '18 at 13:32
  • 1
    No it's not possible. If it was then you'd be able to write your own version of MATLAB, with access to all MATLAB functionality, without purchasing MATLAB. – Phil Goddard May 29 '18 at 14:14
  • @PhilGoddard does that mean I have to write code in MATLAB (Say Add 2 numbers) and then deploy it on client machine containing MATLAB Runtime ? – Abhishek Singh May 29 '18 at 14:33
  • Can you help me with an example ? – Abhishek Singh May 29 '18 at 14:33
  • Look at the documentation for the MATLAB Compiler. It has plenty of examples. – Phil Goddard May 29 '18 at 19:33

1 Answers1

0

No it's not possible. If it was then you'd be able to write your own version of MATLAB, with access to all MATLAB functionality, without purchasing MATLAB.

-- Phil Goddard(From Comments)

Abhishek Singh
  • 10,243
  • 22
  • 74
  • 108