User`s manual
Working with Java Arrays
5-39
This works the same way on an N-dimensional Java array structure. Using the
colon operator as a single subscripted index into the array produces a linear
array composed of all of the elements of the original array.
Note Java and MATLAB arrays are stored differently in memory. This is
reflected in the order they are given in a linear array. Java array elements are
stored in an order that matches the rows of the matrix, (
11, 12, 13, ... in the
array shown above). MATLAB array elements are stored in an order that
matches the columns, (11, 21, 31, ...).
Using END in a Subscript
You can use the end keyword in the first subscript of an access statement. The
first subscript references the top-level array in a multilevel Java array
structure.
Note Using end on lower level arrays is not valid due to the potentially
ragged nature of these arrays (see “The Shape of the Java Array” on
page 5-32). In this case, there is no consistent end value to be derived.
The following example displays data from the third to the last row of Java
array
dblArray.
last2rows = dblArray(3:end, :)
last2rows =
java.lang.Double[][]:
[31] [32] [33] [34] [35]
[41] [42] [43] [44] [45]
Assigning to a Java Array
You assign values to objects in a Java array in essentially the same way as you
do in a MATLAB array. Although Java and MATLAB arrays are structured
quite differently, you use the same command syntax to specify which elements
you want to assign to. See “How MATLAB Represents the Java Array” on
page 5-30 for more information on Java and MATLAB array differences.