User`s manual
Working with Java Arrays
5-37
element at the intersection of row 3 and column 4. Sometimes it is more
advantageous to use just a single subscript. MATLAB provides this capability
(see the section on “Advanced Indexing” in the Using MATLAB manual).
Indexing into a MATLAB matrix using a single subscript references one
element of the matrix. Using the MATLAB matrix shown here,
matlabArray(3)
returns a single element of the matrix.
matlabArray = [11 12 13 14 15; 21 22 23 24 25; ...
31 32 33 34 35; 41 42 43 44 45]
matlabArray =
11 12 13 14 15
21 22 23 24 25
31 32 33 34 35
41 42 43 44 45
matlabArray(3)
ans =
31
Indexing this way into a Java array of arrays references an entire subarray of
the overall structure. Using the
dblArray Java array, that looks the same as
matlabArray shown above, dblArray(3) returns the 5-by-1 array that makes
up the entire third row.
row3 = dblArray(3)
row3 =
java.lang.Double[]:
[31]
[32]
[33]
[34]
[35]
This is a useful feature of MATLAB as it allows you to specify an entire array
from a larger array structure, and then manipulate it as an object.
Using the Colon Operator
Use of the MATLAB colon operator (:) is supported in subscripting Java array
references. This operator works just the same as when referencing the contents
of a MATLAB array. Using the Java array of
java.lang.Double objects shown