Operations on Objects

Object Operations

A fundamental purpose of objects is to contain data and facilitate ways to manipulate that data. Objects often define their own version of ordinary MATLAB® functions that work with the object. For example, you can create a timeseries object and pass the object to plot:

ts = timeseries(rand(100,1),.01:.01:1,'Name','Data1');
plot(ts)

However, MATLAB does not call the standard plot function. MATLAB calls the timeseries plot method, which can extract the data from the timeseries object and create a customized graph.

Help on Objects

Suppose that you use an audioplayer object to play audio with MATLAB. To play audio, load audio data into MATLAB and create an audioplayer:

load('handel','Fs','y')
chorus = audioplayer(y,Fs);

The audioplayer function creates an object that you access using the object variable chorus. MATLAB stores the audio source and other information in the object properties.

Here are the properties and values for the chorus instance of the audioplayer:

chorus
chorus = 

Click the link to get the documentation on audioplayer objects.

The object’s documentation discusses the purpose of the object and describes the properties and methods that you use when working with objects of that class.

You can also list the methods to see what operations you can perform. Pass the object to the methods function to see the list:

methods(chorus)
Methods for class audioplayer:

audioplayer   getdisp       pause         resume        stop          
delete        horzcat       play          set           vertcat       
get           isplaying     playblocking  setdisp

To play the audio, use the play method:

play(chorus)

Functions to Test Objects

These functions provide logical tests, which are useful when using objects in ordinary functions.

FunctionDescription
isa

Determine whether an argument is an object of specific class.

isequal

Determine if two objects are equal, which means both objects are of the same class and size and their corresponding property values are equal.

a == b (eq)

Determine if handle variable a refers to the same object as handle variable b.

isobject

Determine whether input is a MATLAB object

Functions to Query Class Components

These functions provide information about object class components.

FunctionDescription
class

Return class of object.

enumeration

Display class enumeration members and names.

events

List event names defined by the class.

methods

List methods implemented by the class.

methodsview

List methods in separate window.

properties

List class property names.

Related Topics