MATLAB BUILDER JA 2 Guía de usuario Pagina 57

  • Descarga
  • Añadir a mis manuales
  • Imprimir
  • Pagina
    / 292
  • Tabla de contenidos
  • MARCADORES
  • Valorado. / 5. Basado en revisión del cliente
Vista de pagina 56
Passing Arguments to and from Java
M-function in the order in which they appear in the array. Here is an example
of how you might use the
mysum method in a Java program:
public double getsum(double[] vals) throws MWException
{
myclass cls = null;
Object[] x = {vals};
Object[] y = null;
try
{
cls = new myclass();
y = cls.mysum(1, x);
return ((MWNumericArray)y[0]).getDouble(1);
}
finally
{
MWArray.disposeArray(y);
if (cls != null)
cls.dispose();
}
}
In this example, an Object array of length 1 is created and initialized with
a reference to the supplied
double array. This argument is passed to the
mysum method. The result is known to be a scalar double, so the code returns
this
double value with the statement:
return ((MWNumericArray)y[0]).getDouble(1);
Cast the return value to MWNumericArray and invoke the getDouble(int)
method to return the f irst element in the array as a primitive double value.
Code Fragment: Passing Array Inputs. The next example performs
a more general calculation:
public double getsum(Object[] vals) throws MWException
{
myclass cls = null;
Object[] x = null;
3-11
Vista de pagina 56
1 2 ... 52 53 54 55 56 57 58 59 60 61 62 ... 291 292

Comentarios a estos manuales

Sin comentarios