MATLAB BUILDER JA 2 Uživatelská příručka Strana 92

  • Stažení
  • Přidat do mých příruček
  • Tisk
  • Strana
    / 292
  • Tabulka s obsahem
  • KNIHY
  • Hodnocené. / 5. Na základě hodnocení zákazníků
Zobrazit stránku 91
4 Using MWArra y Classes
00-12]
Calling newSparse. The call to newSparse passes three arrays: an array of
matrix data (
x), an array containing the row indices of x (rowindex), and an
array of column indices of
x (colindex). The number of rows (4) and columns
(4) are also passed, as well as the type (
MWClassID.DOUBLE):
double[] x = { 2.0, -1.0, -1.0, 2.0, -1.0,
-1.0, 2.0, -1.0, -1.0, 2.0 };
int[] rowindex = {1, 2, 1, 2, 3, 2, 3, 4, 3, 4};
int[] colindex = {1, 1, 2, 2, 2, 3, 3, 3, 4, 4};
MWNumericArray a =
MWNumericArray.newSparse(rowindex, colindex, x, 4, 4,
MWClassID.DOUBLE);
Constructing the Arra y Without Setting Rows and Columns. You could
have passed just the row and column arrays and let the
newSparse method
determine the number of rows and columns from the maximum values of
rowindex and colindex as follows:
MWNumericArray a = MWNumericArray.newSparse(rowindex, colindex,
x, MWClassID.DOUBLE);
Constructing the Array from a Full M a trix. You can also construct a
sparse array from a full matrix using
newSparse.Thenextexamplerewrites
the previous example using a full matrix:
double[][] x = {{ 2.0, -1.0, 0.0, 0.0},
{-1.0, 2.0, -1.0, 0.0},
{ 0.0 -1.0, 2.0, -1.0},
{ 0.0, 0.0, -1.0, 2.0 }};
MWNumericArray a = MWNumericArray.newSparse(x,
MWClassID.DOUBLE);
4-16
Zobrazit stránku 91
1 2 ... 87 88 89 90 91 92 93 94 95 96 97 ... 291 292

Komentáře k této Příručce

Žádné komentáře