Plotting. 2 Initializing Vectors colon operator x = 1:2:10 x = 1 3 5 7 9 y = 0:0.1:0.5 y = 0 0.1 0.2 0.3 0.4 0.5.

Slides:



Advertisements
Similar presentations
CSE 123 Plots in MATLAB. Easiest way to plot Syntax: ezplot(fun) ezplot(fun,[min,max]) ezplot(fun2) ezplot(fun2,[xmin,xmax,ymin,ymax]) ezplot(fun) plots.
Advertisements

Introduction to Engineering MATLAB – 11 Plotting - 4 Agenda Multiple curves Multiple plot.
Plotting Selim Aksoy Bilkent University Department of Computer Engineering
Lecture (4) Plotting & Programming (1) Eng. Osama Talaat 1.
Introduction to Graphing Using MATLAB. Line Graphs  Useful for graphing functions  Useful for displaying data trends over time  Useful for showing.
Matlab Graphics S. Awad, Ph.D. M. Corless, M.S.E.E. E.C.E. Department University of Michigan-Dearborn Introduction to Matlab: 2D Graphics.
Slide deck by Dr. Greg Reese Miami University MATLAB An Introduction With Applications, 5 th Edition Dr. Amos Gilat The Ohio State University Chapter 5.
1. Overview 2. plot in 2D 3. Plot in 3D 4. Other possible charts 5. Engineers: label your plots! 6. Plots & Polynomial Plotting 11.
MATLAB’s extensive, device-independent plotting capabilities are one of its most powerful features. They make it very easy to plot any data at any time.
MA/CS375 Fall MA/CS 375 Fall 2002 Lecture 4.
MATLAB GRAPHICS 2-D.
MATLAB - Lecture 22A Two Dimensional Plots / Chapter 5 Topics Covered:
EGR106 Week 6 MATLAB FILES Two Dimensional Plots Multiple Plots
Chapter 2 MATLAB Fundamentals.
Vectors and Plotting Selim Aksoy Bilkent University Department of Computer Engineering
MATLAB Week 3 17 November Outline Graphics – Basic plotting – Editing plots from GUI – Editing plots from m-file – Advanced plotting commands.
EGR106 Week 4 Two Dimensional Plots Multiple Plots Plot Formatting Homework.
Introduction to Matlab 332:202 Discrete Mathematics Spring 2007.
Lecture 9 Plotting in 2-D Plotting in 2-D, Plotting Multiple Curves, Plotting with Figures, Plot Settings, Scaling, Legends © 2007 Daniel Valentine. All.
Introduction to Matlab Jianguo Wang CSSCR September 2009.
EPSII 59:006 Spring Outline Managing Your Session File Usage  Saving Workspace  Loading Data Files  Creating M-files More on Matrices Review.
MATLAB Fundamentals.
Chapter 5 Review: Plotting Introduction to MATLAB 7 Engineering 161.
MATLAB INTRO CONTROL LAB1  The Environment  The command prompt Getting Help : e.g help sin, lookfor cos Variables Vectors, Matrices, and Linear Algebra.
PLOTS AND FIGURES DAVID COOPER SUMMER Plots One of the primary uses for MATLAB is to be able to create publication quality figures from you data.
ENG College of Engineering Engineering Education Innovation Center 1 2D Plots 1 in MATLAB Topics Covered: 1.Plotting basic 2-D plots The plot()
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Introduction to MATLAB 7 for Engineers Chapter 5 Advanced.
1 "A picture is worth a thousand words." Graphical representation is useful for: Error detection - you can locate outliers in a dataset, program bugs,
The Hong Kong Polytechnic University Industrial Centre 1 MatLAB Lesson 3 : Graphics Edward Cheung Room W311g 2008m.
MATLAB Plotting With MATLAB 1. Two Dimensional Plots The xy plot is the most commonly used plot by engineers The independent variable is usually called.
ELG 3120 Signal and System Analysis 1 Introduction to MATLAB TAs Wei Zhang Ozgur Ekici (Section A)(Section B) ELG 3120 Lab Tutorial 1.
COMP 116: Introduction to Scientific Programming Lecture 5: Plotting, Scripts and publishing.
Lecture 2 - Matlab Introduction CVEN 302 June 5, 2002.
A L I MAM M OHAMMAD B IN S AUD I SLAMIC U NIVERSITY C OLLEGE OF S CIENCES D EPARTMENT OF M ATHEMATICS MATLAB 251 : MATH SOFTWARE Introduction to MATLAB.
ENG 1181 College of Engineering Engineering Education Innovation Center MATLAB – 2D Plots 1 Go to the class drive: ---> MatLab - Graphing ---> Seed Files.
Master in Optical Fiber Communications and Photonic Technologies Foundations of Digital Transmission - Fall quarter Introduction to Matlab.
Matlab Screen  Command Window  type commands  Current Directory  View folders and m-files  Workspace  View program variables  Double click on a.
Plot (x-values, y-values) >> x = linspace (-3, 3, 20); >> x = linspace (-3, 3, 20); >> y = 2*x – 1; >> y = 2*x – 1; >> plot (x, y) >> plot (x, y)
UW CSE 190p Section 7/26, Summer 2012 Dun-Yu Hsiao.
MATLAB 程式設計 Learning Arrays and x-y Plotting 方煒 台大生機系.
Recap Chapter 5 “Plotting” Two Dimensional Plots Simple x-y Plots Titles, Labels and Grids Multiple Plots.
EGR 106 Lecture 6 2-D Plotting Graphical presentation has become the standard method to show technical information. Engineers use plots to analyze, visualize,
1. Overview 2. plot in 2D 3. Plot in 3D 4. Other possible charts 5. Engineers: label your plots! 6. Plots & Polynomial Plotting 11.
Sept. 26, 2005 Lecture 6 - By Paul Lin 1 CPET 190 Lecture 6 Problem Solving with MATLAB
EGR 115 Introduction to Computing for Engineers 2D Plotting – Part I Wednesday 17 Sept 2014 EGR 115 Introduction to Computing for Engineers.
1 Lecture 5 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.
MATLAB ® for Engineers, Holly Moore Fourth Edition, Global Edition © Pearson Education Limited 2015 All rights reserved. Figure 5.1 Simple Plot of Time.
NET 222: COMMUNICATIONS AND NETWORKS FUNDAMENTALS ( NET 222: COMMUNICATIONS AND NETWORKS FUNDAMENTALS (PRACTICAL PART) Lab 2 : potting to Matlab Networks.
Outline What is MATLAB MATLAB desktop Variables, Vectors and Matrices Matrix operations Array operations Built-in functions: Scalar, Vector, Matrix Data.
EGR 106 – Week 5 – 2-D Plots Question : Why do engineers use plots? Answer : To analyze, visualize, and present data. Matlab has many useful plotting options.
How to use MATLAB (using M-files) Double click this icon To start Matlab 6.5.
Session III Plotting in MATLAB Rajeev Madazhy Dept of Mechanical Engineering LSU MATLAB Tutorials.
Plotting ELEC 206 Computer Applications for Electrical Engineers Dr. Ron Hayne.
Creating a Plot The plot function can take one or more inputs; e.g. plot (x, y) or plot (y) Note that in the two-argument version, the vectors x and.
3D-Graphs A 3D surface is defined as: z = f(x, y)
Course Information Do not rely on color to distinguish curves (due to black-white printout). Use different line styles to distinguish curves (solid, dashed,
Lecture 25: Exploring data
Matrices and Arrays.
主讲教师: 胡章芳 MATLAB及其工程应用 MATLAB and It’s Engineering Application 主讲教师: 胡章芳
Net 222: Communications and networks fundamentals (Practical Part)
Net 222: Communications and networks fundamentals (Practical Part)
Net 222: Communications and networks fundamentals (Practical Part)
MATLAB How to use (using M-files) Double click this icon
MATLAB How to use (using M-files) Double click this icon
MatLab – 2D Plots 2 MATLAB has many built-in functions and commands to create various types of plots. Instructor notes: We start with an example of some.
MATLAB How to use (using M-files)
Introduction to MATLAB Plotting LAB 3
Plotting Signals in MATLAB
How to Use MATLAB A Brief Introduction.
Introduction to Matlab
Presentation transcript:

Plotting

2 Initializing Vectors colon operator x = 1:2:10 x = y = 0:0.1:0.5 y =

3 Initializing Vectors linspace(x1,x2) generates a row vector of 100 linearly equally spaced points between x1 and x2 linspace(x1,x2,N) generates N points between x1 and x2 x = linspace(10,20,5) x = logspace(x1,x2) can be used for logarithmically equally spaced points

4 Vector Operations Scalar-vector operations x = 1:5 x = y = 2 * x  scalar multiplication y = z = x + 10  scalar addition z =

5 Vector Operations Vector-vector operations (element-by-element operations) x = [ ]; y = [ ]; z = x + y z = z = x.* y z = z = x./ y z =

6 Vector Operations Vector-vector operations (element-by-element operations) z = x.^ y z = Use.*,./,.^ for element-by-element operations Vector dimensions must be the same

7 Plotting: Using Simple xy Plots x =0:1:10 ; y =x.^2-10.*x+15; plot(x,y); title( ' Plot of y = x.^ *x + 15'); xlabel( 'x' ); ylabel( 'y' ); grid on;

8 Plotting: Using Simple xy Plots x = linspace(0, 4*pi); y = sin(x); plot(x,y); title( 'sin(x) for [0,4\pi]' ); xlabel( 'x' ); ylabel( 'y' ); grid on; axis( [ 0 4*pi -1 1 ] );

9 Plotting :Printing a Plot print – f -d saves the figure with the given handle in the format specified by the device -depsEncapsulated PostScript -depscEncapsulated Color PostScript -deps2Encapsulated Level 2 PostScript -depsc2Encapsulated Level 2 Color PostScript -djpeg JPEG image with quality level of nn -dtiffTIFF image -dpngPortable Network Graphics image e.g. print -f1 -dtiff myplot.tif

10 Plotting: Multiple Graphs x=0:pi/100:2*pi; y1=sin(2*x); y2=2*cos(2*x); plot(x,y1,x,y2);

11 Plotting: Multiple Graphs x = linspace(0, 4*pi); y1 = sin(x); y2 = sin(x).^ 2; y3 = y1 + y2; plot(x,y1,'b-'); hold on; plot(x,y2,'r--'); plot(x,y3,'g:'); hold off;

12 Plotting: Line Color, Line Style, Marker Style, and Legends e.g. x=0:1:10; y=x.^2-10.*x+15; plot(x,y,'r--',x,y,'bo'); e.g. x=0:pi/100:2*pi; y1=sin(2*x); y2=2*cos(2*x); plot(x,y1,'k-',x,y2,'b--'); title('Plot of f(x) = sin(2x) and its derivative'); xlabel('x'); ylabel('y'); legend('f(x)','d/dx f(x)'); grid on;

13 line colorline markerline style bgrcmykbgrcmyk blue green red cyan magenta yellow black.ox+*sdv^<>ph.ox+*sdv^<>ph point circle x-mark plus star square diamond triangle (down) triangle (up) triangle (left) triangle (right) pentagram hexagram - : solid dotted dashdot dashed Plotting: Line Color, Line Style, Marker Style, and Legends

14 Plotting: Line Color, Line Style, Marker Style, and Legends x = linspace(0, 4*pi); y1 = sin(x); y2 = sin(x).^ 2; y3 = y1 + y2; plot(x,y1,x,y2,x,y3); legend( 'sin(x)', 'sin(x)^2', 'sin(x) + sin(x)^2' );

15 Plotting: Logarithmic Plots plot both x and y data on linear axes semilogx x : logarithmic axes y: linear axes semilogy y: logarithmic axes x: linear axes loglog x : logarithmic axes y: logarithmic axes e.g x=linspace(0,10); y=x.^2-10*x+25; plot(x,y);

16 Additional Plotting Feature: Controlling axis Plotting Limits Table 3.5 e.g.(eg3_5_1.m) x=-2*pi:pi/20:2*pi; y=sin(x); plot(x,y); title('plot of sin(x) vs x'); grid on; axis([0 pi 0 1]);

17 Additional Plotting Feature: Plotting Multiple Plots on the Same Axes hold on; hold off e.g.(eg3_5_2.m) x=-pi:pi/20:pi; y1=sin(x); y2=cos(x); plot(x,y1,'b-'); hold on; plot(x,y2,'k--'); hold off; legend('sin x','cos x');

18 Additional Plotting Feature: Creating Multiple Figures figure(n) e.g.(eg3_5_3.m) figure(1) x=0:0.05:2; y1=exp(x); plot(x,y1); figure(2); y2=exp(-x); plot(x,y2);

19 Additional Plotting Feature: Subplots subplot(m,n,p) e.g.(eg3_5_4.m) figure(1); subplot(2,1,1) x=-pi:pi/20:pi; y=sin(x); plot(x,y); title('subplot 1 title'); subplot(2,1,2) x=-pi:pi/20:pi; y=cos(x); plot(x,y); title('subplot 2 title');

20 Additional Plotting Feature: Subplots x = -2:0.1:4; y = 3.5.^ (-0.5*x).* cos(6*x); figure(1); subplot(2,1,1); plot(x,y,'r-o'); subplot(2,1,2); plot(x,y,'k--*');

21 Additional Plotting Feature: Enhanced Control of Plotted Lines Plot(x,y,’PropertyName’,value,…) LineWidth MarkerEdgeColor MarkerFaceColor MarkerSize e.g.(eg3_5_5.m) x=0:pi/15:4*pi; y=exp(2*sin(x)); plot(x,y,'-ko', 'LineWidth', 3.0, 'MarkerSize', 6, 'MarkerEdgeColor','r','MarkerFaceColor','g')

22 Additional Plotting Feature: Enhanced Control of Text Strings Text Strings titles, axis labels,etc Stream modifiers \bf - Boldface \it - Italics \rm - Restore normal font \fontname{fontname} – Specify the font name to use \fontsize{fontsize} – Specify font size _{xxx} – Subscripts ^{xxx} - Superscripts Table 3.6: Greek and Mathematical symbols e.g. String \tau_{ind} versus \omega_{itm} \theta varies from 0\circle to 90\circ \bf{B}_{\itS}

23 Additional Plotting Feature: Polar Plots polar(theta,r) e.g. script file: microphone.m % Calculate gain versus angle g = 0.5; theta = 0:pi/20:2*pi; gain = 2*g*(1+cos(theta)); % Plot gain polar (theta,gain,'r-'); title ('\bfGain versus angle \theta');

24 Plotting: Example 3.6 plot_fileter.m r = 16000; c = 1.0e-6; f = 1:2:1000; res = 1./ ( 1 + j*2*pi*f*r*c ); amp = abs(res); phase = angle(res); subplot(2,1,1); loglog(f,amp); title( 'Amplitude response' ); xlabel( 'Frequency (Hz)' ); ylabel( 'Output/Input ratio' ); grid on; subplot(2,1,2); semilogx(f,phase); title( 'Phase response' ); xlabel( 'Frequency (Hz)' ); ylabel( 'Output-Input phase (rad)' ); grid on;

25 Additional Plotting Feature: Annotating and Saving Plots Annotating Editing tool Text tool Arrow tool Line tool Saving

26 Plotting Summary plot(x,y) linear plot of vector y vs. vector x title('text'), xlabel('text'), ylabel('text') labels the figure, x-axis and y-axis grid on/off adds/removes grid lines legend( 'string1', 'string2', 'string3',... ) adds a legend using the specified strings hold on/off allows/disallows adding subsequent graphs to the current graph

27 Plotting Summary axis( [ xmin xmax ymin ymax ] ) sets axes ’ limits v = axis returns a row vector containing the scaling for the current plot axis equal sets the same scale for both axes axis square makes the current axis square in size

28 Plotting Summary semilogy(x,y), semilogx(x,y), loglog(x,y) logarithmic plots of vector y vs. vector x figure(k) makes k the current figure subplot(m,n,p) breaks the figure window into an m-by-n matrix of small axes and selects the p th axes for the current plot clf clears current figure

29 Additional Two-Dimensional Plots Additional Types of 2D Plots: more than 20 types Example: line Stem Stair Bar Pie compass

30 Additional Two-Dimensional Plots: examples Line plot x = -2:0.01:4; y = 3.5.^(-0.5*x).*cos(6*x); plot(x,y); line([0 0],[-3 3],'color','r'); Pie plot grades = [ ]; pie(grades);

31 Additional Two-Dimensional Plots: examples Stairs plot y = 1988:1994; s = [ ]; stairs(y,s); Stem plot y = 1988:1994; s = [ ]; stem(y,s);

32 Additional Two-Dimensional Plots: examples Vertical bar plot y = 1988:1994; s = [ ]; bar(y,s,'r'); Horizontal bar plot y = 1988:1994; s = [ ]; barh(y,s,'g');

33 Additional Two-Dimensional Plots: examples Polar plot t = linspace(0,2*pi,200); r = 3 * cos(0.5*t).^2 + t; polar(t,r); Compass plot u = [ ]; v = [ ]; compass(u,v);

34 Additional Two-Dimensional Plots: examples Histogram x = randn(1,100); hist(x,10); hist(x,20);

35 Additional Two-Dimensional Plots: examples Error bar plot x = 1:10; y = sin(x); e = std(y) * ones(size(x)); errorbar(x,y,e);

36 Additional Two-Dimensional Plots: Plotting Functions Easy to plot: plot a function directly, without the necessity of creating intermediate data arrays. ezplot(fun); ezplot(fun, [xmin xmax]); ezplot(fun, [xmin xmax], figure); Example: ezplot('sin(x)/x',[-4*pi 4*pi]); title('Plot of sinx/x'); grid on; fplot

37 Three-Dimensional Plots: Line Plots plot3 Example: Test_plot.m t = 0:0.1:10; x = exp(-0.2*t).* cos(2*t); y = exp(-0.2*t).* sin(2*t); plot(x,y,'LineWidth',2); title('\bfTwo-Dimensional Line Plot'); xlabel('\bfx'); ylabel('\bfy'); axis square; grid on; Test_plot3.m t = 0:0.1:10; x = exp(-0.2*t).* cos(2*t); y = exp(-0.2*t).* sin(2*t); plot3(x,y,t,'LineWidth',2); title('\bfThree-Dimensional Line Plot'); xlabel('\bfx'); ylabel('\bfy'); zlabel('\bftime'); grid on;

38 Three-Dimensional Plots: Surface, Mesh, Contour Must create three equal-sized arrays Data prepared [x,y]=meshgrid(xstart:xinc:xend, ystart:yinc:yend); [x,y]=meshgrid(-4:0.2:4,-4:0.2:4); Z=f(x,y) z = exp(-0.5*(x.^2+0.5*(x-y).^2)); mesh(x,y,z), surf(x,y,z), contour(x,y,z) e.g. test_contour2.m