Download presentation
Presentation is loading. Please wait.
Published byFelicia Parks Modified over 9 years ago
1
SUNY-New Paltz Computer Simulation Lab Electrical and Computer Engineering Department SUNY – New Paltz “Lecture 5”
2
SUNY-New Paltz objectives MATLAB’s high-level 2-D and 3-D plotting facilities Introduction to graphics
3
SUNY-New Paltz Basic 2-D graphs plot(x, y) plot(rand(1, 20)) ezplot(’tan(x)’) x = 0:pi/40:4*pi; plot(x, sin(x))
4
SUNY-New Paltz Drawing Lines Plot([0 4], [1 3])
5
Exercise SUNY-New Paltz 10 20 10
6
SUNY-New Paltz Exercise Plot a Polygon with N Sides N=9; theta=linspace(0,2*pi,N) plot(cos(theta),sin(theta)) axis equal Find an equation for all points Make 2 vectors for all points (x, y) Plot the vectors
7
SUNY-New Paltz Labels gtext(’text’) grid text(x, y, ’text’) title(’text’) xlabel(’horizontal’) ylabel(’vertical’)
8
SUNY-New Paltz Multiple plots on the same axes - Method 1 hold hold off plot(x,sin(x)); hold plot(x,cos(x));
9
SUNY-New Paltz Multiple plots on the same axes - Method 2 plot(x1, y1, x2, y2, x3, y3,... ) plotyy(x1, y1, x2, y2, x3, y3) plotyy(x,sin(x), x, 10*cos(x))
10
SUNY-New Paltz Multiple plots on the same axes - Method 3 Use Matrices Plot([x;x]’, [sin(x);cos(x)]’;
11
SUNY-New Paltz Line styles, markers and color plot(x, y, ’--’) plot(x, y, ’o’) plot(x, sin(x), x, cos(x), ’om--’) Different Colors: c, m, y, k, r, g, b, w
12
SUNY-New Paltz Axis limits axis( [xmin, xmax, ymin, ymax] ) axis auto v = axis axis manual axis equal
13
SUNY-New Paltz Multiple plots in a figure:subplot subplot(m, n, p) subplot(4, 1, 1) subplot(2, 2, 1) subplot(1, 4, 1)
14
c=['bgrk'] x=0:.1:10; for i=1:4 subplot(2,2,i) plot(x,sin(x+pi/2*i),c(i)) title(['sin(x+' num2str(i-1) '*pi/2)']) end SUNY-New Paltz Exercise Plot 4 sinusoids each lagging pi/2 from the previous one. The first sinusoid should have zero delay.
15
SUNY-New Paltz New Graphical Windows h = figure; figure(h) clf % clear figure cla % clear all figures Handle
16
SUNY-New Paltz Logarithmic plots semilogy(x, y) x = 0:0.01:4; semilogy(x, exp(x)), grid
17
SUNY-New Paltz Polar plots x = r cos(θ), y = r sin(θ), x = 0:pi/40:2*pi; polar(x, sin(2*x)) grid θ r
18
SUNY-New Paltz Plotting rapidly changing mathematical functions fplot x = 0.01:0.001:0. 1; plot(x, sin(1./x)) fplot(’sin(1/x)’, [0.01 0.1]).001.0001
19
SUNY-New Paltz 3-D plots t = 0:pi/50:10*pi; plot3(exp(-0.02*t).*sin(t), exp(-0.02*t).*cos(t),t),... xlabel(’x-axis’), ylabel(’y-axis’), zlabel(’z-axis’) plot3(x, y, z)
20
Exercise 1.Let t run from 0 to 10*pi 2.Plot the circle sin(t) versus cos(t) 3.Plot let the above circle to morph as a spiral by multiplying it by a 1/(10*pi)*t function. 4.Use a 3-D plot to rise the spiral from the x- y plane. SUNY-New Paltz
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.