Documente Academic
Documente Profesional
Documente Cultură
Topics..
2
What is MATLAB ??
Basic Matrix Operations
Script Files and M-files
APPLICATIONS:
Plotting functions ..
Image Processing Basics ..
Robotics Applications ..
GUI Design and Programming
Topics..
3
What is MATLAB ??
Basic Matrix Operations
Script Files and M-files
APPLICATIONS:
Plotting functions ..
Image Processing Basics ..
Robotics Applications ..
GUI Design and Programming
MATLAB
4
MATLAB
5
MATLAB
6
MATLAB
8
ans
pi
eps
inf
NaN
i and j
realmin
realmax
Topics..
11
What is MATLAB ??
Basic Matrix Operations
Script Files and M-files
APPLICATIONS:
Plotting functions ..
Image Processing Basics ..
Robotics Applications ..
GUI Design and Programming
Power
Multiplication
Division
or
NOTE:
^ or .^ a^b
* or .* a*b
/ or ./ a/b
\ or .\ b\a
56/8 = 8\56
- (unary) + (unary)
Addition
+
Subtraction Assignment =
or
or
or
or
a.^b
a.*b
a./b
b.\a
a+b
a-b
a=b
(assign b to a)
>>
...
,
%
;
prompt
continue statement on next line
separate statements and data
start comment which ends at end of line
(1) suppress output
(2) used as a row separator in a matrix
specify range
Less Than
<
Less Than or Equal
Greater Than
Greater Than or Equal
Equal To
Not Equal To
<=
>
>=
==
~=
not
and
or
~
&
|
% highest precedence
% equal precedence with or
% equal precedence with and
MATLAB Matrices
16
MATLAB Matrices
17
a_value=23
a_value =
23
MATLAB Matrices
18
MATLAB Matrices
19
MATLAB Matrices
20
2
5
8
3
6
9
Extracting a Sub-Matrix
21
MATLAB Matrices
22
matrix=[1,2,3;4,5,6;7,8,9]
col_two=matrix( : , 2)
matrix =
1 2 3
4 5 6
7 8 9
col_two =
2
5
8
MATLAB Matrices
23
matrix=[1,2,3;4,5,6;7,8,9]
matrix =
1
4
7
2
5
8
3
6
9
rowvec=matrix(2 : 2 , 1 :
3)
rowvec =
4
Topics..
24
What is MATLAB ??
Basic Matrix Operations
Script Files and M-files
APPLICATIONS:
Plotting functions ..
Image Processing Basics ..
Robotics Applications ..
GUI Design and Programming
Use of M-File
25
Functions,
Click to create
a new M-File
Topics..
28
What is MATLAB ??
Basic Matrix Operations
Script Files and M-files
APPLICATIONS:
Plotting functions ..
Image Processing Basics ..
Robotics Applications ..
GUI Design and Programming
who
whos
help
lookfor
what
clear
clear x y
clc
what
dir
ls
type test
delete test
cd a:
chdir a:
pwd
which test
test.m
if
expression1
% is true
% execute these commands
elseif expression2
% is true
% execute these commands
else
% the default
% execute these commands
end
a=3;
b=[1, 2, 3;4, 5, 6]
b=
1 2 3
4 5 6
c= b+a
% Add a to each element of b
c=
4 5 6
7 8 9
a=3;
b=[1, 2, 3;4, 5, 6]
b=
1 2 3
4 5 6
c = b - a %Subtract a from each element of b
c=
-2 -1 0
1 2 3
a=3;
b=[1, 2, 3; 4, 5, 6]
b=
1 2 3
4 5 6
c = a * b % Multiply each element of b by a
c=
3 6 9
12 15 18
a=3;
b=[1, 2, 3; 4, 5, 6]
b=
1 2 3
4 5 6
c = b / a % Divide each element of b by a
c=
0.3333 0.6667 1.0000
1.3333 1.6667 2.0000
Given A:
Multiply each
element of A by 3
Square each
element of A
MATLAB Toolboxes
39
Signal Processing
Image Processing
Communications
System Identification
Wavelet Filter Design
Control System
Fuzzy Logic
Robust Control
-Analysis and Synthesis
LMI Control
Model Predictive Control
MATLAB Demo
40
why
In case you ever needed a reason
Topics..
42
What is MATLAB ??
Basic Matrix Operations
Script Files and M-files
APPLICATIONS:
Plotting functions ..
Image Processing Basics ..
Robotics Applications ..
GUI Design and Programming
Plot
PLOT Linear plot.
PLOT(X,Y) plots vector Y
versus vector X
SEMILOGY, TITLE,
XLABEL, YLABEL, AXIS,
AXES, HOLD, COLORDEF,
LEGEND, SUBPLOT...
43
Example
x = [-3 -2 -1 0 1 2 3];
y1 = (x.^2) -1;
plot(x, y1,'bo-.');
Plot Properties
Example
44
...
xlabel('x values');
ylabel('y values');
Hold
Example
default mode
HOLD, by itself, toggles the
hold state.
45
...
hold on;
y2 = x + 2;
plot(x, y2, 'g+:');
Subplot
SUBPLOT Create axes in tiled
positions.
SUBPLOT(m,n,p), or
Example
x = [-3 -2 -1 0 1 2 3];
y1 = (x.^2) -1;
% Plot y1 on the top
subplot(2,1,1);
plot(x, y1,'bo-.');
xlabel('x values');
ylabel('y values');
% Plot y2 on the bottom
subplot(2,1,2);
y2 = x + 2;
plot(x, y2, 'g+:');
46
Figure
FIGURE Create figure window.
FIGURE, by itself, creates a
Surface Plot
x = 0:0.1:2;
y = 0:0.1:2;
[xx, yy] = meshgrid(x,y);
zz=sin(xx.^2+yy.^2);
surf(xx,yy,zz)
xlabel('X axes')
ylabel('Y axes')
48
3 D Surface Plot
contourf-colorbar-plot3-waterfall-contour3-mesh-surf
49
Convolution
50
For example,
x = [1 1 1 1 1];
[1 1 1 1 1]
h = [0 1 2 3]; [3 2 1 0]
conv(x,h)
yields y = [0 1 3 6 6 6 5 3]
stem(y);
ylabel(Conv');
xlabel(sample number);
Topics..
51
What is MATLAB ??
Basic Matrix Operations
Script Files and M-files
APPLICATIONS:
Plotting functions ..
Image Processing Basics ..
Robotics Applications ..
GUI Design and Programming
Geometric operations
Neighborhood and block operations
Linear filtering and filter design
Transforms
Image analysis and enhancement
Binary image operations
Region of interest operations
Indexed images
Intensity images
Binary images
RGB images
Indexed Images
[x,map] =
imread('trees.tif');
imshow(x,map);
54
Intensity Images
image =
ind2gray(x,map);
imshow(image);
55
Binary Images
imshow(edge(image));
56
RGB Images
57
Image Display
58
image
Image Conversion
59
Gray2ind
im2bw
Im2double
Im2uint8
Im2uint16
Ind2gray
mat2gray
rgb2gray
rgb2ind
GEOMETRIC OPERATIONS
60
IMAGE ENHANCEMENT
61
Adjust intensity
imadjust
histeq
Noise removal
linear filtering
median filtering
adaptive filtering
>>im2 = histeq(im);
>>imshow(im2)
TRANSFORMS
62
Fourier Transform
-fft2, fftshift, ifft2
Radon Transform
-radon, iradon, phantom
Topics..
63
What is MATLAB ??
Basic Matrix Operations
Script Files and M-files
APPLICATIONS:
Plotting functions ..
Image Processing Basics ..
Robotics Applications ..
GUI Design and Programming
Robotics Application
64
Robotics Application
65
Concept
take image
filter using medfilt2
take the subarray of ball region, find cluster of max
area ,find its centroid
take the subarray of robot region , find cluster of max
area, find its centroid
interpolate the ball using the ball's current and
previous coordinate , give output
Robotics Application
66
MATLAB Code
parport=digitalio('parallel','LPT1');
addline(parport,0:7,'out');
ball_x_prev = 1;
ball_y_prev = 1;
while (1)
% code for acquiring image
filtered_image=medfilt2(bw,[3 3]);
% filter the image
region_ball = filtered_image[20:460,10:575]; % ball region
region_bot = filtered_image[20:460,575:630]; % robot region
label = bwlabel(region_ball,4);
%label the clusters in the region
data = regionprops(label,'basic');
% data ontains properties of clusters in the region
object = find([data.Area]==max([data.Area])) % object conatains the label of the cluster with max
area
Robotics Application
67
ball_x = data(object).Centroid(1);
ball_y = data(object).Centroid(2);
label = bwlabel(region_bot,4);
%label the clusters in the region
data = regionprops(label,'basic');
% data ontains properties of clusters in the region
object =find([data.Area]==max([data.Area])) % object conatains the label of the cluster with max
area
robot_x = data(object).Centroid(1);
robot_y = data(object).Centroid(2);
Topics..
68
What is MATLAB ??
Basic Matrix Operations
Script Files and M-files
APPLICATIONS:
Plotting functions ..
Image Processing Basics ..
Robotics Applications ..
GUI Design and Programming
static text
Axes
70
Checkbox
Frames
Slider
Edit text
Radio Buttons
Push Buttons
Guide Editor
Result Figure
Property Inspector
Thanks
73
Questions ??