Escolar Documentos
Profissional Documentos
Cultura Documentos
Programming in MATLAB
Agenda
0910 1030
Object-oriented programming in
MATLAB
Classes, methods and properties
Encapsulation and inheritance
Events and listeners
1030 1050
BREAK
1050 1145
What is a program?
Data
x = 12
while (x < 100)
x = x+1
if (x == 23)
disp('Hello')
end
end
Code
x = 12
while (x < 100)
x = x+1
if (x == 23)
disp('Hello')
end
end
Assignment
Looping Test
Increment
Test to Act
Take Action
End
End
Actions
Data
value
variable
structure
Actions
4
Transmitting a signal
from a weather balloon
Procedural Programming
Easy to learn
Minimal planning
No formal relationship
between data and functions
Every detail is exposed
Wavelength
Number
Spacing
Location
Determine peaks
Compute FFT
Plot results
Reading
Frequency
Data
Synthesize measurements
Actions
Balloon
Wavelength
Location
Signal
Location
Frequency
Wavelength
Frequency
Data
Number
Sensor
Spacing
Reading
Spacing
Reading
Number
Determine peaks
Sensor
Synthesize measurements
Compute
FFT peaks
Determine
Compute FFT Plot results
Plot results
Synthesize measurements
Actions
Balloon
Location
Signal
Frequency
Wavelength
Data
Sensor
Synthesize measurements
Determine peaksSensor
Synthesize measurements
Compute FFT
Sensor
Determine peaks
Plot results Sensor
Reading
Compute FFT
Reading
Spacing
Plot results
Spacing
Number
Number
Class
Actions
value
variable
structure
class
function
script
command line
Actions
10
Object-Oriented Terminology
Class
Blueprint of an idea
Properties (data)
Methods (actions)
Object
Specific example of a class
Instance
11
12
Objects
Easy to create
Interchangeable
with a structure
No other code changes required
Properties behave similar to field names
Cant add fields arbitrarily
13
Demonstration:
Adding Methods to a Class
14
15
16
Encapsulation
Speed of
Light
Number of Towers
Synthesize
measurements
Tower Spacing
Sensor
Compute
FFT
Sensor Reading
Noise Ratio
etc.
Plot Results
Determine
Peaks
Compute AoA
17
Encapsulation
Speed
of
Separates the
interface
Light
from the implementation
Simplifies
Spacing
Tower
Becomes
Sensor Reading
Number of Towers
etc.
Number of Towers
Noise Ratio
Synthesize
object measurements
use
a building
block
Compute
Plot Results
Determine
Tower Spacing
Peaks
FFT
Sensor
Compute AoA
18
Control access
Access = public
Access = protected
Restrict modification
Constant
Dependent
19
All targets
20
Position
Move Source
Add a method
Signal
21
Inheritance
Subclass substitutes
for the superclass
Allows re-envisioning
and re-implementing
the superclass
22
a = 10000;
b = a;
b = 20000;
disp(a)
a) 10,000
b) 20,000
c) Something else
23
a = analoginput('winsound'); addchannel(a,1);
a.SampleRate = 10000;
b = a;
b.SampleRate = 20000;
disp(a.SampleRate)
a) 10,000
b) 20,000
c) Something else
24
B
Data
Data
Data
>> B = A;
A
A
Data
Data
25
Value Class
Handle Class
MATLAB default
= copies data
= references data
data in workspace
handle in workspace
A
B
Data
Data
Data
26
React to events
Callbacks
27
Events
Created in a handle object
events block in classdef
notify() triggers event
Listeners
Triggers callback function
addlistener()
Useable anywhere
28
29
Agenda
0910 1030
Object-oriented programming in
MATLAB
Classes, methods and properties
Encapsulation and inheritance
Events and listeners
1030 1050
1050 1145
BREAK
Agenda
0910 1030
Object-oriented programming in
MATLAB
Classes, methods and properties
Encapsulation and inheritance
Events and listeners
1030 1050
1050 1145
BREAK
Demo:
Creating a GUI application
32
MATLAB Compiler
MATLAB
Builder EX
.exe
.dll/
.so
Excel
Add-in
MATLAB
Builder JA
MATLAB Builder
NE
www
COM
33
Demo:
Creating a Standalone Executable
34
Royalty-free deployment
3
Toolboxes
MATLAB
Desktop
1
2
End-User
Machine
MATLAB Compiler
36
Suppliers
MATLAB User
Your Organization
Clients
Your Group
Field
engineers
37
Very Flexible
MATLAB Compiler
Source Code
MATLAB Coder
38
Agenda
0910 1030
Object-oriented programming in
MATLAB
Classes, methods and properties
Encapsulation and inheritance
Events and listeners
1030 1050
1050 1145
BREAK
Demo:
Database access with MATLAB
40
Summary
41
Training
http://www.mathworks.se/training-schedule/
Dates
Oct
1st
Oct
4th
Course
3rd
MATLAB Fundamentals
5th
Language
Location
English
Sweden, Stockholm
(City)
English
Sweden, Stockholm
(City)
42
Products
www.mathworks.se
Training
www.mathworks.se/training
Public and on-site courses
Ask us!
43
Questions?
44