JMIWrapper

class JMIWrapper

Interacts with MATLAB via the undocumented Java MATLAB Interface (JMI). This code is inspired by Kamin Whitehouse‘s MatlabControl. Fixes to concurrency bugs in this class have been aided by the feedback of several matlabcontrol users, thank you for your feedback! This class runs inside of MATLAB’s Java Virtual Machine and relies upon the Java MATLAB Interface which is distributed by MathWorks as jmi.jar. It allows for Java to send eval and feval statements to MATLAB and receive results. jmi.jar is not distributed with matlabcontrol as it is the property of MathWorks. If you wish to compile the source code you will need to reference the version of jmi.jar that is distributed with your copy of MATLAB. It is located at matlabroot/java/jar/jmi.jar where matlabroot is the location of your MATLAB installation. The location of matlabroot can be determined by executing the matlabroot command in the MATLAB Command Window. This is the only class in matlabcontrol which directly links against code in jmi.jar. (And therefore also the only class that needs jmi.jar to be on the classpath in order to compile.) Configuration also uses code in jmi.jar but uses reflection to interact with it.

Author:Joshua Kaplan

Methods

eval

static void eval(String command)

exit

static void exit()

Exits MATLAB without waiting for MATLAB to return, because MATLAB will not return when exiting.

Throws:

feval

static void feval(String functionName, Object... args)

getVariable

static Object getVariable(String variableName)

invokeAndWait

static <T> T invokeAndWait(MatlabThreadCallable<T> callable)

Invokes the callable on the main MATLAB thread and waits for the computation to be completed.

Parameters:
  • <T>
  • callable
Throws:

returningEval

static Object[] returningEval(String command, int nargout)

returningFeval

static Object[] returningFeval(String functionName, int nargout, Object... args)

setVariable

static void setVariable(String variableName, Object value)