External Interfaces/API | ![]() ![]() |
Concatenating Java Objects
You can concatenate Java objects in the same way that you concatenate native MATLAB data types. You use either the cat
function or the square bracket operators to tell MATLAB to assemble the enclosed objects into a single object. If all of the objects being operated on are of the same Java class, then the concatenation of those objects will be an array of objects from the same class.
In the following example, the cat
function concatenates two objects of the class java.awt.Point
. The class of the result is also java.awt.Point
.
Note
When using the cat function, the first argument, which specifies the axis along which to perform the concatenation, must be 1. Java objects can only be concatenated along the first axis.
|
point1=java.awt.Point(24,127); point2=java.awt.Point(114,29); cat(1, point1, point2) ans = java.awt.Point[]: [1x1 java.awt.Point] [1x1 java.awt.Point]
In this second example, the MATLAB square bracket operators are used to concatenate two objects of unlike classes. The resultant class is java.lang.Object
, which is the root of the Java class hierarchy.
frame=java.awt.Frame('Sample Frame'); [frame point1] ans = java.lang.Object[]: [1x1 java.awt.Frame] [1x1 java.awt.Point]
![]() | Creating and Using Java Objects | Saving and Loading Java Objects to MAT-Files | ![]() |