Lecture 3
Lecture 3
LECTURE 3
MATLAB Graphing
University of Dar es Salaam
PLOTTING
Examples
• plot(y) produces a linear graph of the elements of y versus the indices
of the elements of y
y=linspace(0,10,10); plot(y)
• If two vectors are specified as arguments, plot(x,y) produces a graph
of y versus x. y and x are of equal length
x = linspace(0,2*pi); y=sin(x) ; plot(x,y)
University of Dar es Salaam
MULTIPLE PLOT
Plotting multiple graphs in
one call
Syntax: >> plot(x,y1,x,y2,x,y3)
Example:
University of Dar es Salaam
PLOT & HOLD • Try this
• Try this
• >> x = [0:0.1:2*pi];
• >> y = sin(x); z=cos(2*x)
• Plot the graph of y vs x
and hold
• Plot the graph of z vs x
• Inset graph title, legend
and label the axes.
• Grid on and grid off
University of Dar es Salaam
THE SUBPLOT FUNCTION
subplot(2,2,4) % p=4
subplot(1,2,2) % p=2
University of Dar es Salaam
EXAMPLES…
University of Dar es Salaam
EXAMPLES…
University of Dar es Salaam
EXAMPLES…
University of Dar es Salaam
LOGARITHMIC PLOTS