Introduction To Object-Oriented Programming in MATLAB - Mathworks PDF
Introduction To Object-Oriented Programming in MATLAB - Mathworks PDF
Introduction To Object-Oriented Programming in MATLAB - Mathworks PDF
Programming in MATLAB
Jamie Winter
Sr. Account Manager
Abhishek Gupta
Application Engineer
Object-oriented programming
Classes in MATLAB
2
What is a program?
Data
x = 12
while (x < 100)
x = x+1
if (x == 23)
x = 12 disp('Hello')
while (x < 100) end
x = x+1 end
if (x == 23)
disp('Hello')
end Assignment
end Looping Test
Increment
Test to Act
Code Take Action
End
End
Actions 3
Progression of Programming Techniques
value Data
variable
structure
function
script
command line
Algorithm
4
Example: Sensor Array
Transmitting a signal
from a weather balloon
5
Procedural Programming
Easy to learn
Minimal planning
There is no formal
relationship between
data and functions.
Every detail is exposed.
6
Data and Actions to Implement
Reading
Synthesize measurements
Frequency
Data Actions
7
Related Data and Actions
Data Actions
8
Grouping Related Data and Actions
Sensor
Balloon Synthesize measurements
Location Determine peaksSensor
Compute FFT Synthesize measurements
Sensor Determine peaks
Plot results Sensor
Signal Reading Compute FFT
Frequency Spacing Reading
Plot results
Wavelength Number Spacing
Number
9
Progression of Programming Techniques
value Data
variable
structure
(properties)
Level of Abstraction / Sophistication
class
(methods)
function
script
command line
Algorithm
10
Object-Oriented Terminology
Class
– Outline of an idea
– Properties (data)
– Methods (algorithms)
An element of
the set – object
Object
– Specific example of a class
– Instance Defined set – class
11
Agenda
Object-oriented programming
Classes in MATLAB
12
Demonstration: Building a Simple Class
13
Objects
Are interchangeable
with a structure
– No other code changes are required.
– Properties behave similar to field names.
– Fields can’t be added arbitrarily.
14
Demonstration:
Adding Methods to a Class
Start from a sensor class
with existing properties
Sensor
Synthesize measurements
Determine peaks
Add a method to compute
Compute FFT
angle of arrival (AoA) Plot results
15
Objects with Methods
16
Agenda
Object-oriented programming
Classes in MATLAB
17
Taking Methods and Properties Further
Control access
Create constants
18
Demonstration: Applying Attributes
Control access
Access = public
Access = protected
Restrict modification
Constant
Dependent
19
Encapsulation
Speed of
Noise Ratio Sensor Reading
Light
Determine
Tower Spacing Compute Peaks
FFT
Compute AoA
Sensor
20
Encapsulation
Simplifies
Number object
of Towers use Number of Towers
etc.
Synthesize
measurements
Plot Results
Becomes a building block
Determine
Tower Spacing Compute Tower Spacing
Peaks
FFT
Compute AoA
Sensor
21
Using a Class as a Building Block
The Balloon
All Moving Radar Blips
22
Demonstration:
Creating a Moving Target
Define a new class
for moving blips
23
Inheritance
Subclass substitutes
for the superclass
Allows re-envisioning
and re-implementing
the superclass
24
Object-Oriented Programming in MATLAB
25
Additional Resources
26
Questions and Answers
27