Digital Image Processing in Matlab
Digital Image Processing in Matlab
Digital Image Processing in Matlab
PROCESSING IN
MATLAB
LECTURE 3
Handling multiple plots
Displaying multiple plots in a graph- hold on
command
X=1:1:50;
Y=X.^3;
A=1:1:100;
B=A.^2;
plot(X, Y, 'r')
hold on;
plot(A, B, 'g')
‘hold on’ example
4
x 10
14
12
10
0
0 10 20 30 40 50 60 70 80 90 100
The ‘figure’ command
Opens up a new figure for the next plot
X=1:1:50;
Y=X.^3;
A=1:1:100;
B=A.^2;
plot(X, Y, 'r')
figure;
plot(A, B, 'g')
‘figure’ example
4
x 10
14
12
10
8
10000
6 9000
8000
4
7000
2
6000
0 5000
0 5 10 15 20 25 30 35 40 45 50
4000
3000
2000
1000
0
0 10 20 30 40 50 60 70 80 90 100
To close existing figures
>>close([1 3])
closes figures 1 and 3
>>close all
closes all open figures (useful in scripts/functions)
subplot(N, M, 1) or subplot(NM1)
subplot(2, 2, 1)
plot(x1, y1)
Consider these 4 sets
x1=1:1:50;
y1=x1.^1;
x2=1:1:100;
y=x2.^2;
x3=1:1:75;
y3=x3.^3;
x4=1:1:60;
y4=x4.^4
No of rows=2 and no of columns=2 in the main
figure…..
subplot(2, 2, 1)
plot(x1, y1, 'r')
subplot(2, 2, 2)
plot(x2, y2, 'g')
subplot(2, 2, 3)
plot(x3, y3, 'k')
subplot(2, 2, 4)
plot(x4, y4, 'b')
Playing with the Plot
Try this
Other properties
title('Stress-Strain');
xlabel(‘this is x axis');
legend('Steel','Aluminum','Tungsten');
ylabel(‘this is y axis’)
grid on
Plot……
Stress-Strain
9
Steel
8 Aluminum
Tungsten
6
this is y ax is
1
1 1.2 1.4 1.6 1.8 2 2.2 2.4 2.6 2.8 3
this is x axis
Check out what these commands do to your plot
xlim([-pi pi]);
ylim([-1 1]);
To specify both at once, use axis:
axis([-pi pi -1 1]);
sets the x axis limits between -pi and pi and the y axis
You can set the x and y limits to any values you wish.
Axis Modes
As your homework test these commands after a
plot to see what happens
An exercise
Use MATLAB to plot the following function for
-1≤ t ≤ 5 sec (in any increment you want).
1 2 3
1 2 3
1 2 3
Similarly..
a=[1 2 3];
b=[5 6 7];
[X Y]= meshgrid(a, b)
Surface Plots
In certain cases, it is better to visualize surfaces in
3D
Define x and y
x is a row vector starting from –pi and ending at pi
(increments= 0.1)
y=x
Apply meshgrid on x and y to get new ‘X’ and ‘Y’
Define Z to be the multiplication product of sin(X)
and cos (Y).
Introducing the ‘surf’ command
>>surf(X, Y, Z)
Surf- to make a surface
Surf Options
Contour command
clear
clc
x=-pi:0.1:pi;
y=-pi:0.1:pi;
[X,Y]=meshgrid(x,y);
Z =sin(X).*cos(Y);
surf(X,Y,Z)
hold on
contour(X,Y,Z,'LineWidth',2)
0.2
-0.2
-0.4
-0.6
-0.8
-1