MATLAB BUILDER JA 2 Guia do Utilizador Página 57

  • Descarregar
  • Adicionar aos meus manuais
  • Imprimir
  • Página
    / 292
  • Índice
  • MARCADORES
  • Avaliado. / 5. Com base em avaliações de clientes
Vista de página 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 página 56
1 2 ... 52 53 54 55 56 57 58 59 60 61 62 ... 291 292

Comentários a estes Manuais

Sem comentários