User`s guide
3 Programming
return ret;
}
finally
{
MWArray.disposeArray(y);
if (cls != null)
cls.dispose();
}
}
The getrandvectors m ethod returns a two-dimensional double array w ith
a triangular structure. The length of the
ith row equals i. Such a rrays are
commonly referred to a s jagged arrays. Jagged arrays are easily supported in
Java becaus e a Java matrix is just an array of arrays.
Handling Return Values
Thepreviousexamplesusedthefactthatyouknewthetypeand
dimensionality of the output argument. In the case that this information is
unknown, or can vary (as is possible in M-programming), the code that calls
the method m ight need to query the type and dimensionality of the output
arguments.
Therearetwobasicwaystodothis.Youcandooneofthefollowing:
• UsereflectionsupportintheJavalanguagetoqueryanyobjectforitstype.
• Use several methods provided by the
MWArray class to query information
about the underlying MATLAB array.
Code Fragment: Using Java Reflection
This code sample calls the myprimes method, and then determines the type
using reflection. The example assumes that the output is returned as a
numeric matrix but the exact numeric type is unknown.
public void getprimes(int n) throws MWException
{
myclass cls = null;
Object[] y = null;
3-14