User`s manual
Working with Java Arrays
5-45
java.lang.Double[][]:
[11] [12] [13] [14]
[21] [22] [23] [24]
[ 0] [ 0] [ 0] [ 0]
Creating a Copy of a Java Array
You can create an entirely new array from an existing Java array by indexing
into the array to describe a block of elements, (or subarray), and assigning this
subarray to a variable. The assignment copies the values in the original array
to the corresponding cells of the new array.
As with the example in section “Creating a New Array Reference” on page 5-44,
an original array is created and initialized. But, this time, a copy is made of the
array contents rather than copying the array reference. Changes made using
the reference to the new array do not affect the original.
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 contents -----
newArray = origArray(:,:);
newArray(3,:) = java.lang.Double(0);
origArray
origArray =
java.lang.Double[][]:
[11] [12] [13] [14]
[21] [22] [23] [24]
[31] [32] [33] [34]