Defining Concatenation for Your Class
Default Concatenation
You can concatenate objects into arrays. For example, suppose
you have three instances of the class MyClass, obj1, obj2, obj3.
You can form various arrays with these objects using brackets. Horizontal
concatenation calls horzcat:
HorArray = [obj1,obj2,obj3];
HorArray is a 1–by–3 array
of class MyClass. You can concatenate the objects
along the vertical dimension, which calls vertcat:
VertArray = [obj1;obj2;obj3]
VertArray is a 3–by–1 array
of class MyClass. You can use the cat function to concatenate arrays along
different dimensions. For example:
ndArray = cat(3,HorArray,HorArray);
ndArray is a 1–by–3–by–2
array.
You can overload horzcat, vertcat,
and cat to produce specialized behaviors in your
class. Note that you must overload both horzcat and vertcat whenever
you want to modify object concatenation because MATLAB uses both functions
for any concatenation operation.
Example of horzcat and vertcat
Example — Adding Properties to a Built-In Subclass
Back to Top
 | Methods That Modify Default Behavior | | Displaying Objects in the Command Window |  |
Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
Get the Interactive Kit