User`s manual

5 Calling Java from MATLAB
5-44
% Concatenate the two along the second dimension.
d3 = cat(2,d1,d2)
d3 =
java.lang.Double[][]:
[2] [4] [6] [ 8] [10]
[3] [5] [7] [ 9] [11]
[4] [6] [8] [10] [12]
Creating a New Array Reference
Because Java arrays in MATLAB are references, assigning an array variable to
another variable results in a second reference to the array.
Consider the following example where two separate array variables reference
a common array. The original array,
origArray, is created and initialized. The
statement
newArrayRef = origArray creates a copy of this array variable.
Changes made to the array referred to by
newArrayRef also show up in the
original array.
origArray = javaArray('java.lang.Double', 3, 4);
for m = 1:3
for n = 1:4
origArray(m,n) = java.lang.Double((m * 10) + n);
end
end
origArray
origArray =
java.lang.Double[][]:
[11] [12] [13] [14]
[21] [22] [23] [24]
[31] [32] [33] [34]
% ----- Make a copy of the array reference -----
newArrayRef = origArray;
newArrayRef(3,:) = java.lang.Double(0);
origArray
origArray =