External Interfaces |
Concatenating Java Arrays
You can concatenate arrays of Java objects in the same way as arrays of other data types. (To understand how scalar Java objects are concatenated by MATLAB see Concatenating Java Objects.)
Use either the cat
function or the square bracket ([]
) operators. This example horizontally concatenates two Java arrays: d1
, and d2
.
% Construct a 2-by-3 array of java.lang.Double. d1 = javaArray('java.lang.Double',2,3); for m = 1:3 for n = 1:3 d1(m,n) = java.lang.Double(n*2 + m-1); end; end; d1 d1 = java.lang.Double[][]: [2] [4] [6] [3] [5] [7] [4] [6] [8] % Construct a 2-by-2 array of java.lang.Double. d2 = javaArray('java.lang.Double',2,2); for m = 1:3 for n = 1:2 d2(m,n) = java.lang.Double((n+3)*2 + m-1); end; end; d2 d2 = java.lang.Double[][]: [ 8] [10] [ 9] [11] [10] [12] % 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]
Assigning to a Java Array | Creating a New Array Reference |
© 1994-2005 The MathWorks, Inc.