3 Programming
}
else if (a instanceof byte[][])
{
byte[][] x = (byte[][])a;
/* (do something with x...) */
}
else
{
throw new MWException(
"Bad type returned from myprimes");
}
}
This example uses the toArray method (see “Methods to Copy, Convert,
and Compare MWArrays” on p age 4-49) to return a Java primitive array
representing the underlying MATLAB array. The
toArray method works just
like
getData in the previous examples, except that the returned array has the
same dimensionality as the underlying MATLAB array.
Code Fragment: Using MWArray Query
The next example uses the MWArray classID method (see “Methods to
Return Information About an MWArray” on page 4-40) to determine the
type of the underlying MATLAB array. It also checks the dimensionality by
calling
numberOfDimensions. If any unexpected information is returned, an
exception is thrown. It then checks the
MWClassID and processes the array
accordingly.
public void getprimes(int n) throws MWException
{
myclass cls = null;
Object[] y = null;
try
{
cls = new myclass();
y = cls.myprimes(1, new Double((double)n));
3-16
Komentarze do niniejszej Instrukcji