MATLAB Object-Oriented Programming
Handle Object Behavior In this section... “What Is a Handle?” on page 1-9 “Copies of Handles” on page 1-9 “Handle Objects Modifi ...
MATLAB software includes audio data that you can load and use to create an audioplayer object. This sample load audio data, crea ...
Passing a nonhandle variable to a function does not affect the original variable that is in the caller’s workspace. For example, ...
function modifySampleRate(audioObj,sr) audioObj.SampleRate = sr; end Create an audioplayer object and pass it to the modifySampl ...
load gong Fs y gongSound = audioplayer(y,Fs); The output argument, gongSound, is a handle variable. Calling delete deletes the o ...
gongSound.SampleRate Invalid or deleted object. Functions and methods that access object properties cause an error: play(gongSou ...
Basic Example 2 ...
Create a Simple Class In this section... “Design Class” on page 2-2 “Create Object” on page 2-3 “Access Properties” on page 2-3 ...
For a summary of class syntax, see classdef. To use the class: Save the class definition in a .m file with the same name as the ...
Call Methods Call the roundOff method on object a: roundOff(a) ans = 1.0500 Pass the object as the first argument to a method th ...
By adding this constructor to the class definition, you can create an object in one step: a = BasicClass(pi/3) a = BasicClass wi ...
a(3) = BasicClass(7); roundOff(a) ans = 2.8000 0.8700 7.0000 Overload Functions Classes can implement existing functionality, su ...
BasicClass Code Listing Here is the BasicClass definition after adding the features discussed in this topic: classdef BasicClass ...
...
MATLAB Classes Overview “Role of Classes in MATLAB” on page 3-2 “Developing Classes — Typical Workflow” on page 3-8 “Representi ...
Role of Classes in MATLAB In this section... “Classes” on page 3-2 “Some Basic Relationships” on page 3-4 Classes In the MATLAB ...
p1 + p2 the plus operation must be able to add polynomial objects because the polynomial class defines this operation. When you ...
Some Basic Relationships This section discusses some of the basic concepts used by MATLAB classes. Classes A class is a definiti ...
All Numbers Integers Positive Integers Positives Reals The “is a” relationship is a good way to determine if it is appropriate t ...
Objects A class is like a template for the creation of a specific instance of the class. This instance or object contains actual ...
«
1
2
3
4
5
6
7
8
9
10
»
Free download pdf