MATLAB BUILDER JA 2 User's Guide Page 60

  • Download
  • Add to my manuals
  • Print
  • Page
    / 292
  • Table of contents
  • BOOKMARKS
  • Rated. / 5. Based on customer reviews
Page view 59
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
Page view 59
1 2 ... 55 56 57 58 59 60 61 62 63 64 65 ... 291 292

Comments to this Manuals

No comments