Main Content

连接方法

Default Concatenation

You can concatenate objects into arrays. For example, suppose that you have three instances of the classMyClass,obj1,obj2,obj3. You can form arrays of these objects using brackets. Horizontal concatenation callshorzcat:

HorArray = [obj1,obj2,obj3];

HorArrayis a 1-by-3 array of classMyClass. You can concatenate the objects along the vertical dimension, which callsvertcat:

VertArray = [obj1;obj2;obj3]

VertArrayis a 3-by-1 array of classMyClass. To concatenate arrays along different dimensions, use thecatfunction. For example:

ndArray = cat(3,HorArray,HorArray);

ndArrayis a 1-by-3-by-2 array.

方法重载

Overloadhorzcat,vertcat, andcatto produce specialized behaviors in your class. Overload bothhorzcatandvertcatwhenever you want to modify object concatenation because MATLAB®uses both functions for any concatenation operation.

Related Topics