1 / 20

Computer Simulation Lab

Computer Simulation Lab. “Lecture 5”. Electrical and Computer Engineering Department SUNY – New Paltz. Introduction to graphics. objectives MATLAB’s high-level 2-D and 3-D plotting facilities. Basic 2-D graphs. plot(x, y) plot(rand(1, 20)) ezplot(’tan(x)’) x = 0:pi/40:4*pi;

thea
Télécharger la présentation

Computer Simulation Lab

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Computer Simulation Lab “Lecture 5” Electrical and Computer Engineering Department SUNY – New Paltz SUNY-New Paltz

  2. Introduction to graphics objectives MATLAB’s high-level 2-D and 3-D plotting facilities SUNY-New Paltz

  3. Basic 2-D graphs plot(x, y) plot(rand(1, 20)) ezplot(’tan(x)’) x = 0:pi/40:4*pi; plot(x, sin(x)) SUNY-New Paltz

  4. Drawing Lines Plot([0 4], [1 3]) SUNY-New Paltz

  5. Exercise 10 10 10 20 SUNY-New Paltz

  6. 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 SUNY-New Paltz

  7. Labels • gtext(’text’) • grid • text(x, y, ’text’) • title(’text’) • xlabel(’horizontal’) • ylabel(’vertical’) SUNY-New Paltz

  8. Multiple plots on the same axes - Method 1 • hold • hold off • plot(x,sin(x)); • hold • plot(x,cos(x)); SUNY-New Paltz

  9. 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)) SUNY-New Paltz

  10. Multiple plots on the same axes - Method 3 • Use Matrices • Plot([x;x]’, [sin(x);cos(x)]’; SUNY-New Paltz

  11. 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 SUNY-New Paltz

  12. Axis limits axis( [xmin, xmax, ymin, ymax] ) axis auto v = axis axis manual axis equal SUNY-New Paltz

  13. Multiple plots in a figure:subplot subplot(m, n, p) subplot(4, 1, 1) subplot(2, 2, 1) subplot(1, 4, 1) SUNY-New Paltz

  14. Exercise • Plot 4 sinusoids each lagging pi/2 from the previous one. The first sinusoid should have zero delay. 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

  15. New Graphical Windows Handle h = figure; figure(h) clf % clear figure cla % clear all figures SUNY-New Paltz

  16. Logarithmic plots semilogy(x, y) x = 0:0.01:4; semilogy(x, exp(x)), grid SUNY-New Paltz

  17. Polar plots r x = r cos(θ), y = r sin(θ), θ x = 0:pi/40:2*pi; polar(x, sin(2*x)) grid SUNY-New Paltz

  18. Plotting rapidly changing mathematical functions fplot .001 x = 0.01:0.001:0.1; plot(x, sin(1./x)) .0001 fplot(’sin(1/x)’, [0.01 0.1]) SUNY-New Paltz

  19. 3-D plots plot3(x, y, z) 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’) SUNY-New Paltz

  20. Exercise • Let t run from 0 to 10*pi • Plot the circle sin(t) versus cos(t) • Plot let the above circle to morph as a spiral by multiplying it by a 1/(10*pi)*t function. • Use a 3-D plot to rise the spiral from the x-y plane. SUNY-New Paltz

More Related