MATLAB Object-Oriented Programming

(Joyce) #1

Methods That Modify Default Behavior


In this section...
“How to Customize Class Behavior” on page 17-2
“Which Methods Control Which Behaviors” on page 17-2
“Overload Functions and Override Methods” on page 17-4

How to Customize Class Behavior


There are functions that MATLAB calls implicitly when you perform certain actions with
objects. For example, a statement like [B(1);A(3)] involves indexed reference and
vertical concatenation.

You can change how user-defined objects behave by defining methods that control specific
behaviors. To change a behavior, implement the appropriate method with the name and
signature of the MATLAB function.

Which Methods Control Which Behaviors


The following table lists the methods to implement for your class and describes the
behaviors that they control.

Class Method to Implement Description
Concatenating Objects
cat, horzcat, and vertcat Customize behavior when concatenating objects

See “Subclasses of Built-In Types with Properties”
on page 12-68
Creating Empty Arrays
empty Create empty arrays of the specified class. See
“Empty Arrays” on page 10-8
Displaying Objects

17 Specialize Object Behavior

Free download pdf