MATLAB BUILDER JA 2 Betriebsanweisung Seite 95

  • Herunterladen
  • Zu meinen Handbüchern hinzufügen
  • Drucken
  • Seite
    / 292
  • Inhaltsverzeichnis
  • LESEZEICHEN
  • Bewertet. / 5. Basierend auf Kundenbewertungen
Seitenansicht 94
Guidelines for Working with MWArray Classes
Examples of Using set. T he following examples construct the 2-by-2 matrix
of the p revious exam p le using the
set method. The first example uses a
single index:
int[] dims = {2, 2};
MWNumericArray a =
MWNumericArray.newInstance(dims, MWClassID.DOUBLE,
MWComplexity.REAL);
int index = 0;
double[] values = {1.0, 3.0, 2.0, 4.0};
for (int index = 1; index <= 4; index++)
a.set(index, values[index-1]);
Here is the same exam ple, but this tim e using an index array:
int[] dims = {2, 2};
MWNumericArray a =
MWNumericArray.newInstance(dims, MWClassID.DOUBLE,
MWComplexity.REAL);
int[] index = new int[2];
int k = 0;
for (index[0] = 1; index[0] <= 2; index[0]++)
{
for (index[1] = 1; index[1] <= 2; index[1]++)
a.set(index, ++k);
}
The sparse array example can likewise be rewritten using set as follows:
MWNumericArray a =
MWNumericArray.newSparse(4, 4, 10, MWClassID.DOUBLE,
MWComplexity.REAL);
int[] index = {1, 1};
for (index[0] = 1; index[0] <= 4; index[0]++)
{
for (index[1] = 1; index[1] <= 4; index[1]++)
{
if (index[1] == index[0])
4-19
Seitenansicht 94
1 2 ... 90 91 92 93 94 95 96 97 98 99 100 ... 291 292

Kommentare zu diesen Handbüchern

Keine Kommentare