MATLAB Object-Oriented Programming

(Joyce) #1

Concatenating Objects of Different Classes


In this section...
“Basic Knowledge” on page 10-18
“MATLAB Concatenation Rules” on page 10-18
“Concatenating Objects” on page 10-19
“Calling the Dominant-Class Constructor” on page 10-19
“Converter Methods” on page 10-21

Basic Knowledge


The material presented in this section builds on an understanding of the information
presented in the following sections.


  • “Construct Object Arrays” on page 10-2

  • “Valid Combinations of Unlike Classes”


MATLAB Concatenation Rules


MATLAB follows these rules for concatenating objects:


  • MATLAB always attempts to convert all objects to the dominant class.

  • User-defined classes take precedence over built-in classes like double.

  • If there is no defined dominance relationship between any two objects, then the left-
    most object dominates (see “Class Precedence” on page 6-23).


When converting to a dominant class during concatenation or subscripted assignment,
MATLAB searches the non-dominant class for a conversion method that is the same name
as the dominant class. If such a conversion method exists, MATLAB calls it. If a
conversion method does not exist, MATLAB calls the dominant class constructor on the
non-dominant object.

It is possible for the dominant class to define horzcat, vertcat, or cat methods that
modify the default concatenation process.

10 Object Arrays

Free download pdf