User`s manual

5 Calling Java from MATLAB
5-58
Converting to the MATLAB double Data Type
Using the double function in MATLAB, you can convert any Java object or
array of objects to the MATLAB
double data type. The action taken by the
double function depends on the class of the object you specify:
If the object is an instance of a numeric class (
java.lang.Number or one of
the classes that inherit from that class), then MATLAB uses a preset
conversion algorithm to convert the object to a MATLAB
double.
If the object is not an instance of a numeric class, MATLAB checks the class
definition to see if it implements a method called
toDouble. Note that
MATLAB uses
toDouble to perform its conversion of Java objects to the
MATLAB
double data type. If such a method is implemented for this class,
MATLAB executes it to perform the conversion.
If you are using a class of your own design, you can write your own
toDouble
method to perform conversions on objects of that class to a MATLAB
double.
This enables you to specify your own means of data type conversion for
objects belonging to your own classes.
Note If the class of the specified object is not java.lang.Number, does not
inherit from that
java.lang.Number, and it does not implement a toDouble
method, then an attempt to convert the object using the
double function
results in an error in MATLAB.
The syntax for the
double command is as follows, where object is a Java object
or Java array of objects.
double(object);
Converting to the MATLAB char Data Type
With the MATLAB char function, you can convert java.lang.String objects
and arrays to MATLAB data types. A single
java.lang.String object converts
to a MATLAB character array. An array of
java.lang.String objects converts
to a MATLAB cell array, with each cell holding a character array.
If the object specified in the
char command is not an instance of the
java.lang.String class, then MATLAB checks its class to see if it implements
a method named
toChar. If this is the case, then MATLAB executes the toChar