This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Create Java Array References

Java® arrays in MATLAB® are references. Assigning an array variable to another variable results in a second reference to the array, not a copy of the array. For example, create and initialize origArray.

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]

Create a second reference to the array newArrayRef.

newArrayRef = origArray;

Change the array referred by newArrayRef. The changes also show up in origArray.

newArrayRef(3,:) = java.lang.Double(0);
origArray
origArray =

  java.lang.Double[][]:

    [11]    [12]    [13]    [14]
    [21]    [22]    [23]    [24]
    [ 0]    [ 0]    [ 0]    [ 0]

Related Topics