MATLAB BUILDER JA 2 User's Guide Page 87

  • Download
  • Add to my manuals
  • Print
  • Page
    / 292
  • Table of contents
  • BOOKMARKS
  • Rated. / 5. Based on customer reviews
Page view 86
Guidelines for Working with MWArray Classes
Constructing Jagged Arrays
The previous examples constructed rectangular Java arrays and used these
arrays to initialize MATLAB arrays. Multidimensional arrays in Java are
implemented a s arrays of arrays, which meansthatitispossibletoconstruct
a Java array in which each row can have a different number of columns. Such
arrays are commonly referred to as jagged arrays.
MWNumericArray constructors support jagged arrays by constructing a
rectangular array and padding with zeros any miss ing elements. The
resulting MATLAB array will have a column count equal to the largest
column count in any row of the input array. For example, the following two
statements construct a 5-by-5
double matrix from a 5-by-5 Java double array
in which the number of columns in the ith row equals
i:
double[][] pascalsTriangle = {
{1.0},
{1.0, 1.0},
{1.0, 2.0, 1.0},
{1.0, 3.0, 3.0, 1.0},
{1.0, 4.0, 6.0, 4.0, 1.0}
};
MWNumericArray a1 = new MWNumericArray(pascalsTriangle);
The resulting M ATLAB array has the following structure:
[10000
11000
12100
13310
14641]
Passing Arguments to Constructors as MWClassID. In some cases, the
constructor converts the input to the specified type passed as an
MWClassID
value. When this value is omitted, the inputs are converted according to
default conversion rules.
For example, each of the following statements creates a real scalar
double
array w ith a value of 1.0:
4-11
Page view 86
1 2 ... 82 83 84 85 86 87 88 89 90 91 92 ... 291 292

Comments to this Manuals

No comments