Professional Documents
Culture Documents
Experiment [5]
Overview of MATLAB Plotting
rotate 3D Insert
colorbar Insert
zoom in/zoom out data cursor 1legend Hide / display
plot tools
SIGNAL AND SYSTEMS LABORATORY
command Syntax
linspace linspace(min,max,points)
logspace logspace(min,max,points)
plot plot(x,y,'property')
stem stem(x,y,'property')
xlabel xlabel('title of x-axis')
ylabel ylabel('title of y-axis')
title title('title of graph')
text text(x,y,'text')
legend Display a legend on graph
grid on
to display and hide the grid on the figure background
grid off
hold on
Multiple data in one graph
hold off
figure Multiple data in multiple graphs
subplot Multiple data in one graph but in different figures
Simple Plots:
The basic MATLAB graphing procedure, for example in 2D, is to take a vector (x) that
contains N samples x=(x1, … ,xN) and a vector (y) of N samples, y (yl, … , yN), locate the
points (xi, yi), with i =1, 2, …, N and then join them by straight lines. x and y both have
to be row arrays or column arrays of the same length.
clc
clear all
x=0:0.01:10;
y=sin (x);
plot (x, y);
xlabel ('input');
ylabel('output');
title('wave');
grid
2
SIGNAL AND SYSTEMS LABORATORY
(color style marker) is a string containing one to four characters (enclosed in single
quotation marks) constructed from a color, a line style, and a marker type as follows:
• Color strings are 'c', 'm', 'y', 'r', 'g', 'b', 'w', and 'k'. These correspond to cyan, magenta,
yellow, red, green, blue, white, and black.
• Line style strings are '-' for solid, '--' for dashed, ':' for dotted, '-.' for dash-dot. Omit the
line style for no line.
• The marker types are '+', 'o', '*', and 'x', and the filled marker types are 's' for square, 'd'
for diamond, '^' for up triangle, 'v' for down triangle, '>' for right triangle, '<' for left
triangle, 'p' for pentagram, 'h' for hexagram, and none for no marker.
Note: If you specify a marker type but not a line style, MATLAB draws only the marker.
For example: plot(x,y,'ks');
plots black squares at each data point, but does not connect the markers with a line. The
statement plot(x,y,'r:+');
plots a red dotted line and places plus sign markers at each data point.
x = 0:pi/100:2*pi; 0.4
y = sin(x); 0.2
y2 = sin(x-0.25); 0
y3 = sin(x-0.5); -0.2
plot(x,y,x,y2,x,y3); -0.4
-1
0 1 2 3 4 5 6 7
legend('sin(x)','sin(x-.25)','sin(x-.5)');
3
SIGNAL AND SYSTEMS LABORATORY
x = 0:pi/100:2*pi;
y = sin(x);
y2 = sin(x-0.25);
y3 = sin(x-0.5);
hold on
plot(x,y);
plot (x,y2);
plot (x,y3);
hold off
3. using subplot:
The subplot command enables you to display multiple plots in the same window or
print them on the same piece of paper. Typing:
Subplot(m, n, p);
partitions the figure window into an m-by-n matrix of small subplots and selects the p th
subplot for the current plot. For example, these statements plot data in two different sub
regions of the figure window:
x= 0:0.1:2*pi;
y1=sin(x);
y2=cos(x);
subplot(2,1,1)
plot(x,y1);
grid on
subplot(2,1,2)
plot(x,y2)
grid on
x= 0:0.1:2*pi;
y1=sin(x);
y2=cos(x);
subplot(1,2,1)
plot(x,y1);
grid on
subplot(1,2,2)
plot(x,y2)
grid on
4
SIGNAL AND SYSTEMS LABORATORY
4. using figures
clear all
x= 0:0.l:2*pi;
yl = sin(x);
y2 =cos(x);
plot(x,y1);
grid on
figure;
plot(x,y2);
grid on
Experiment:
3) y= | x | for -6 ≤ x ≤ 6
a- in one figure
b- in different figures
c- in one figure but different parts