Guidelines for Working with MWArray Classes
Here, each cell is initialized with a Java a rray, and default conversion rules
are used to create the MATLAB array for each cell.
Constructing an MWCellArray Containing Complex Arrays. The next
example creates a helper function that constructs a cell array containing a list
of complex
double arrays. The real and imaginary parts of each cell are passed
in the
re and im arrays, respectively. The new cell array has dimensions
1-by-
N,whereN is the leng th of the inp ut arrays, which must be the same.
MWCellArray createNumericCell(Object[] re, Object[] im)
throws MWException
{
if (re == null || im == null)
throw new MWException("Invalid input");
if (re.length != im.length)
throw new MWException(
"Input arrays must be the same length");
MWCellArray a = null;
MWNumericArray x = null;
try
{
a = new MWCellArray(1, re.length);
for (int k = 1; k <= re.length; k++)
{
x = new MWNumericArray(re[k-1], im[k-1],
MWClassID.DOUBLE);
a.set(k, x);
x.dispose();
x = null;
}
return a;
}
catch (Exception e)
{
if (a != null)
a.dispose();
4-33
Komentarze do niniejszej Instrukcji