Line Plots: % Turn On Grid Lines For This Plot
Line Plots: % Turn On Grid Lines For This Plot
LINE PLOTS
PLOTTING IN
MATLAB
SAMPLE SYNTAX
GRAPH
t = 0:pi/100:2*pi;
y = sin(t);
plot(t,y)
grid on % Turn on grid lines for this plot
SAMPLE SYNTAX
You can plot multiple graphs in one call to plot
using x-y pairs. MATLAB automatically cycles
through a predefined list of colors (determined
by the axes ColorOrder property) to allow
discrimination between sets of data.
y = sin(t);
y2 = sin(t-0.25);
y3 = sin(t-0.5);
plot(t,y,t,y2,t,y3)
8/15/2013
GRAPH
GRAPH
plot(x,y,':squarey')
plots a yellow dotted line and places square
markers at each data point. If you specify a
marker type, but not a line style, only the marker
is plotted.
8/15/2013
SAMPLE SYNTAX
GRAPH
x = -pi:pi/10:pi;
y = tan(sin(x)) - sin(tan(x));
plot(x,y,'--rs','LineWidth',2,...
'MarkerEdgeColor','k',...
'MarkerFaceColor','g',...
'MarkerSize',10)
GRAPH
SAMPLE SYNTAX
semilogx(1:100,'+')
hold all % hold plot and cycle line colors
plot(1:3:300,1:100,'--')
hold off
grid on % Turn on grid lines for this plot
x = 0:pi/15:4*pi;
y = -exp(2*cos(x));
plot(x,y,'r+')
8/15/2013
EXAMPLE #1
Use Matlab to draw the graph of f (x) = x2 2x
3 on the interval *1, 3+.
x = 0:pi/15:4*pi;
y = -exp(2*cos(x));
plot(x,y,'-r',x,y,'ok')
SYNTAX
GRAPH
>> x=-1:.1:3;y=x.2-2*x-3;
>> plot(x,y)
>> xlabel(x-axis)
>> ylabel(y-axis)
>> title(The graph of f(x) = x2 - 2x - 3)
>> grid on
EXAMPLE #2
Sketch the graphs of f (x) = 1/x and g(x) = log(x
1) on the interval [2, 5].
SYNTAX
>> x=2:.1:5;
>> f=1./x;
>> g=log(x-1);
>> plot(x,f,-,x,g,--)
>> legend(y = f(x),y = g(x))
8/15/2013
GRAPH
PLOTTING IN MATLAB
LABORATORY EXERCISE #3