Main Content

com.mathworks.matlab.types.HandleObject

Abstract Java class to represent MATLAB handle objects

Description

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.

Creation

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

Examples

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

Version History

Introduced in R2016b