Main Content


Abstract Java class to represent MATLAB handle objects


Java® represents handle objects that are passed from MATLAB® as instances of the HandleObject class. When passing a handle object back to MATLAB, Java passes a reference to the HandleObject instance. This reference can be either an array or a scalar, depending on the original handle object passed to Java from MATLAB.


You cannot construct a HandleObject in Java. You only can pass a handle object to the MATLAB session in which it was originally created.


expand all

This example starts a shared MATLAB session and creates a containers.Map object in the MATLAB workspace. The statement evaluated in the MATLAB workspace returns a handle variable that refers to the Map object.

The engine getVariable function returns the MATLAB handle variable as a HandleObject instance. This instance is used to call the MATLAB keys function to obtain the Map keys.

import com.mathworks.engine.MatlabEngine;
import com.mathworks.matlab.types.*;

MatlabEngine engine = MatlabEngine.startMatlab();
engine.eval("cm = containers.Map({'id','name'},{11,'mw'});");
HandleObject handle = engine.getVariable("cm");
String[] cells = engine.feval("keys", handle);
Introduced in R2016b