User`s guide
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