User`s guide

4 Using MWArra y Classes
double, float, byte, short, int, long, java.lang.Boolean, subclasses of
java.lang.Number,andjava.lang.String.
Examples of Using set and get Methods. This example constructs a
random sparse logical matrix with a specified fraction of nonzero elemen ts:
MWLogicalArray getRandomSparse(int m, int n, double fillFactor)
{
if (m < 0 || n < 0)
throw new IllegalArgumentException(
"Dimensions must be positive");
if (fillFactor < 0.0 || fillFactor > 1.0)
throw new IllegalArgumentException(
"Fill factor must be between 0.0 and 1.0");
int nsize = (int)(m*n*fillFactor);
MWLogicalArray a = newSparse(m, n, nsize);
if (nsize == 0)
return a;
while (a.numberOfNonZeros() < nsize)
{
int k = (int)(m*n*java.lang.Math.random());
a.set((k != 0 ? k : 1), true);
}
return a;
}
This example toggles all elements of a logical array from true/false to
false/true:
void toggleArray(MWLogicalArray a)
{
for (int k = 1; k <= a.numberOfElements(); k++)
a.set(k, !getBoolean(k));
}
Working with Character Arrays
The MWCharArray classprovidesaJavainterfacetoaMATLABchar array.
4-26