User`s manual
5 Calling Java from MATLAB
5-60
pstruct.xpoints
ans =
14
42
98
124
pstruct.xpoints(3) = 101;
Converting to a MATLAB Cell Array
Use the cell function to convert a Java array or Java object into a MATLAB
cell array. Elements of the resulting cell array will be of the MATLAB type (if
any) closest to the Java array elements or Java object.
The syntax for the
cell command is as follows, where object is a Java object
or Java array of objects.
cell(object);
In the following example, a MATLAB cell array is created in which each cell
holds an array of a different data type. The
cell command used in the first line
converts each type of object array into a cell array.
import java.lang.* java.awt.*;
% Create a Java array of double
dblArray = javaArray('java.lang.Double', 1, 10);
for m = 1:10
dblArray(1, m) = Double(m * 7);
end
% Create a Java array of points
ptArray = javaArray('java.awt.Point', 3);
ptArray(1) = Point(7.1, 22);
ptArray(2) = Point(5.2, 35);
ptArray(3) = Point(3.1, 49);
% Create a Java array of strings
strArray = javaArray('java.lang.String', 2, 2);
strArray(1,1) = String('one'); strArray(1,2) = String('two');
strArray(2,1) = String('three'); strArray(2,2) = String('four');