User`s manual
Working with Java Arrays
5-35
for m = 1:4
for n = 1:5
dblArray(m,n) = java.lang.Double((m*10) + n);
end
end
dblArray
dblArray =
java.lang.Double[][]:
[11] [12] [13] [14] [15]
[21] [22] [23] [24] [25]
[31] [32] [33] [34] [35]
[41] [42] [43] [44] [45]
Another Way to Create a Java Array
You can also create an array of Java objects using syntax that is more typical
to MATLAB. For example, the following syntax creates a 4-by-5 MATLAB
array of type double and assigns zero to each element of the array.
matlabArray(4,5) = 0;
You use similar syntax to create a Java array in MATLAB, except that you
must specify the Java class name. The value being assigned,
0 in this example,
is stored in the final element of the array, javaArray
(4,5). All other elements
of the array receive the empty matrix.
javaArray(4,5) = java.lang.Double(0)
javaArray =
java.lang.Double[][]:
[] [] [] [] []
[] [] [] [] []
[] [] [] [] []
[] [] [] [] [0]
Note You cannot change the dimensions of an existing Java array as you can
with a MATLAB array. The same restriction exists when working with Java
arrays in the Java language. See the example below.