External Interfaces/API    

Concatenating Java Arrays

The degree of concatenation you can perform on Java arrays is limited due to the significant structural differences between MATLAB and Java arrays. The counterpart of a multidimensional MATLAB array in Java is a considerably more complex structure built upon arrays of the one-dimensional Java array. The individual lower level arrays in this structure can be of varying lengths, giving the overall array structure an uneven, or ragged, look. This quality in the Java array results in a greater chance of incompatibility between arrays and thus limits the degree to which they can be joined together by the MATLAB concatenation operation.

If the Java arrays being concatenated are of the same class (or the class of one array is assignable to that of the other(s)), then they are considered to be assignment compatible. In this case, the class of the resultant array is the class that is compatible with all of the constituent arrays. And the length of the resultant array is the sum of the lengths of each constituent array.

Consider the two arrays of java.awt.Frame shown below. The frmArray1 array is a 3-by-5 array of Frame objects. The frmArray2 array is a 7-by-12 array of the same. The cat function is used to concatenate the two arrays. The result is a 10-element array of the java.awt.Frame class.

If the constituent arrays are not assignment compatible, then the resultant array is of the java.lang.Object class. The length of the array is equal to the number of arrays being combined in the concatenation. For example,


 Assigning to a Java Array Creating a New Array Reference