MATLAB1
MATLAB1
Presented by
Sahil Mahto
Topics..
2
What is MATLAB ??
Basic Matrix Operations
Script Files and M-files
Some more Operations and Functions
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
Some more Operations and Functions
APPLICATIONS:
Plotting functions ..
Image Processing Basics ..
Robotics Applications ..
GUI Design and Programming
MATLAB
4
MATLAB
6
MATLAB
8
» a=5;
» b=a/2
b=
2.5000
»
MATLAB Variable Names
9
What is MATLAB ??
Basic Matrix Operations
Script Files and M-files
Some more Operations and Functions
APPLICATIONS:
Plotting functions ..
Image Processing Basics ..
Robotics Applications ..
GUI Design and Programming
- (unary) + (unary)
Addition + a+b
Subtraction - a-b
Assignment = a=b (assign b to a)
Other MATLAB symbols
13
>> 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
MATLAB Matrices
16
Scalars are matrices with only one row AND one column
MATLAB Matrices
17
» a_value=23
a_value =
23
MATLAB Matrices
18
rowvec =
12 14 63
MATLAB Matrices
19
colvec =
13
45
-2
MATLAB Matrices
20
» matrix = [1 , 2 , 3 ; 4 , 5 ,6 ; 7 , 8 , 9]
matrix =
1 2 3
4 5 6
7 8 9
Extracting a Sub-Matrix
21
sub_matrix = matrix ( r1 : r2 , c1 : c2 ) ;
MATLAB Matrices
22
» matrix=[1,2,3;4,5,6;7,8,9] » col_two=matrix( : , 2)
matrix = col_two =
1 2 3
4 5 6 2
7 8 9 5
8
MATLAB Matrices
23
matrix =
» rowvec=matrix(2 : 2 , 1 :
3)
1 2 3
4 5 6 rowvec =
7 8 9
4 5 6
Topics..
24
What is MATLAB ??
Basic Matrix Operations
Script Files and M-files
Some more Operations and Functions
APPLICATIONS:
Plotting functions ..
Image Processing Basics ..
Robotics Applications ..
GUI Design and Programming
Use of M-File
25
Click to create
a new M-File
Topics..
28
What is MATLAB ??
Basic Matrix Operations
Script Files and M-files
Some more Operations and Functions
APPLICATIONS:
Plotting functions ..
Image Processing Basics ..
Robotics Applications ..
GUI Design and Programming
Some Useful MATLAB commands
29
if expression1 % is true
% execute these commands
elseif expression2 % is true
% execute these commands
else % the default
% execute these commands
end
MATLAB Repetition Structures
33
» 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
Scalar - Matrix Subtraction
35
» 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
Scalar - Matrix Division
37
» 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:
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
Topics..
42
What is MATLAB ??
Basic Matrix Operations
Script Files and M-files
Some more Operations and Functions
APPLICATIONS:
Plotting functions ..
Image Processing Basics ..
Robotics Applications ..
GUI Design and Programming
Plot
Example
PLOT Linear plot.
x = [-3 -2 -1 0 1 2 3];
PLOT(X,Y) plots vector Y y1 = (x.^2) -1;
versus vector X
plot(x, y1,'bo-.');
PLOT(Y) plots the columns of
Y versus their index
PLOT(X,Y,S) with plot
symbols and colors
See also SEMILOGX,
SEMILOGY, TITLE,
XLABEL, YLABEL, AXIS,
AXES, HOLD, COLORDEF,
LEGEND, SUBPLOT...
43
Plot Properties
Example
44
Hold
Example
HOLD Hold current graph. ...
hold on;
HOLD ON holds the current
y2 = x + 2;
plot and all axis properties so
plot(x, y2, 'g+:');
that subsequent graphing
commands add to the existing
graph.
HOLD OFF returns to the
default mode
HOLD, by itself, toggles the
hold state.
45
Subplot
46
Figure
Example
x = [-3 -2 -1 0 1 2 3];
y1 = (x.^2) -1;
% Plot y1 in the 1st Figure
plot(x, y1,'bo-.');
xlabel('x values');
ylabel('y values');
% Plot y2 in the 2nd Figure
figure
y2 = x + 2;
plot(x, y2, 'g+:');
47
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
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
Some more Operations and Functions
APPLICATIONS:
Plotting functions ..
Image Processing Basics ..
Robotics Applications ..
GUI Design and Programming
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
GEOMETRIC OPERATIONS
60
Adjust intensity
>>im2 = histeq(im);
imadjust >>imshow(im2)
histeq
Noise removal
linear filtering
median filtering
adaptive filtering
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
Some more Operations and Functions
APPLICATIONS:
Plotting functions ..
Image Processing Basics ..
Robotics Applications ..
GUI Design and Programming
Robotics Application
64
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
Topics..
68
What is MATLAB ??
Basic Matrix Operations
Script Files and M-files
Some more Operations and Functions
APPLICATIONS:
Plotting functions ..
Image Processing Basics ..
Robotics Applications ..
GUI Design and Programming
Graphical User Interface
69
Checkbox Slider
Edit text
Guide Editor
Questions ??