User`s guide
3 Programming
Object[] y = null;
try
{
x = new Object[vals.length];
for (int i = 0; i < vals.length; i++)
x[i] = new MWNumericArray(vals[i], MWClassID.DOUBLE);
cls = new myclass();
y = cls.mysum(1, x);
return ((MWNumericArray)y[0]).getDouble(1);
}
finally
{
MWArray.disposeArray(x);
MWArray.disposeArray(y);
if (cls != null)
cls.dispose();
}
}
This version of getsum takes an array of Object as input and converts each
valuetoa
double array. The l ist of double arrays is then passed to the mysum
function, w here it calculates the total sum of each input array.
Code Fragment: Passing a Variable Number of Outputs
When present, varargout arguments are handled in the same way that
varargin arguments are handled. Consider the following M-function:
function varargout = randvectors
% RANDVECTORS Returns a list of random vectors.
% VARARGOUT = RANDVECTORS Returns a list of random
% vectors such that the length of the ith vector = i.
% This file is used as an example for the MATLAB
% Builder for Java product.
% Copyright 2001-2006 The MathWorks, Inc.
for i=1:nargout
3-12