Lab 4
Lab 4
(x(8),y(8))
(x(2),y(2))
SIMPLE PLOTTING COMMANDS
Command Effect
plot Plots in linear coordinates as a continuous function
stem Plots in linear coordinates as a discrete function
log Logarithmic x & y axis
bar Bar Graph
polar Polar coordinates
PLOT VECTORS or MATRICES: plot(X,Y)
• If X and Y are vectors, vector Y versus vector X is
plotted. (X & Y should be of equal length)
Command Effect
xlabel Labels x-axis
ylabel Labels y-axis
grid Adds a grid to the plot
gtext Allows positioning of text with the mouse
text Allows placing text at specified coordinates of the plot
axis Allows changing the x and y axes
figure Create a figure for plotting
figure (n) Make figure number n the current figure
hold on Allows multiple plots to be superimposed on the same axes
hold off Release hold on current plot
close(n) Close figure number n
Add Title and Axis Labels to Plot:
SUBPLOT (subplot(a,b,c))
subplot(m,n,p) divides the current figure into an m-by-n grid and creates
axes in the position specified by p. The first subplot is the 1st col of the 1st
row, the second subplot is 2nd col of the 1st row and so on.
1 2
3 4
Upper and Lower Subplots:
Multiple Subplots
Multiple Subplots with Varying sizes
Upper and Lower Subplots:
STEM PLOTS
The stem command plots discrete sequence data. stem(Y) plots the data
sequence, Y, as stems that extend from a baseline along the x-axis. The data
values are indicated by circles terminating each stem.
stem(X,Y) plots the data sequence, Y, at values specified by X. The X and Y inputs
must be vectors or matrices of the same size. Additionally, X can be a row or
column vector and Y must be a matrix with length(X) rows.
To create a stem plot for random discrete values, use the following code:
Plotting a Sinusoid
Plotting Multiple Data Series
Fill in Plot Markers
Specifying Stem and Marker Options
UNDERSTANDING (To built a unitstep
function) tic;
t(index) 1
t = -10:1:10 %discrete values
2 3 4 5 6 7 8 9 10 11 12 13 14 15
toc;
16 17 18 19 20 21
values -10 -9 -8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8 9 10
Now, built another array such that for all the negative values of t it is ‘0’
and ‘1’ for rest. We will get an array like following.
u(index) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
values 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1
Now, if we plot ‘u’ against ‘t’, we get a unit-step function. But, we need
to be flexible while coding as the user can enter array containing any values
BAR GRAPH
bar(y) creates a bar graph with one bar for each element in y. If y is an m-by-n
matrix, then bar creates m groups of n bars.