MATLAB BUILDER JA 2 Guide de l'utilisateur Page 60

  • Télécharger
  • Ajouter à mon manuel
  • Imprimer
  • Page
    / 292
  • Table des matières
  • MARQUE LIVRES
  • Noté. / 5. Basé sur avis des utilisateurs
Vue de la page 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
Vue de la page 59
1 2 ... 55 56 57 58 59 60 61 62 63 64 65 ... 291 292

Commentaires sur ces manuels

Pas de commentaire