Net 222: Communications and networks fundamentals (Practical Part)

Slides:



Advertisements
Similar presentations
Lab # 03- SS Basic Graphic Commands. Lab Objectives: To understand M-files principle. To plot multiple plots on a single graph. To use different parameters.
Advertisements

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.
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.
2D Plots 1 ENGR 1181 MATLAB 12.
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.
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
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.
Plotting. Basic Plotting Two vectors of x and y values needed. Vectors need to be of the same length, but not necessarily of the same geometry. For example,
An introduction to Plotting in MATLAB Rikard Johansson Department of Biomedical Engineering (IMT) Linköping University
Chapter 5 Review: Plotting Introduction to MATLAB 7 Engineering 161.
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()
„  1999 BG Mobasseri1 9/18/2015 June 2 GRAPHICS IN MATLAB- PART I BASIC PLOTTING.
ELG 3120 Signal and System Analysis 1 Introduction to MATLAB TAs Wei Zhang Ozgur Ekici (Section A)(Section B) ELG 3120 Lab Tutorial 1.
Ranjeet Department of Physics & Astrophysics University of Delhi Working with Origin.
COMP 116: Introduction to Scientific Programming Lecture 5: Plotting, Scripts and publishing.
ENG 1181 College of Engineering Engineering Education Innovation Center MATLAB – 2D Plots 1 Go to the class drive: ---> MatLab - Graphing ---> Seed Files.
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)
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,
Introduction to Matlab  Matlab is a software package for technical computation.  Matlab allows you to solve many numerical problems including - arrays.
1 Lecture 5 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.
Introduction to Engineering MATLAB – 9 Plotting - 2 Agenda Formatting plots.
NET 222: COMMUNICATIONS AND NETWORKS FUNDAMENTALS ( NET 222: COMMUNICATIONS AND NETWORKS FUNDAMENTALS (PRACTICAL PART) Lab 2 : potting to Matlab Networks.
CS100A, Fall 1998, Lecture 201 CS100A, Fall 1998 Lecture 20, Tuesday Nov 10 More Matlab Concepts: plotting (cont.) 2-D arrays Control structures: while,
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.
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.
Going Green By Ima Librarian
Computer Application in Engineering Design
Plotting Chapter 5.
3D-Graphs A 3D surface is defined as: z = f(x, y)
Lecture 25.
Ch3 Graphics Overview of Plotting Editing Plots
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
Two-Dimensional Plots
Matrices and Arrays.
Introduction To MATLAB
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
Microsoft Office Illustrated Introductory, Windows XP Edition
Using Charts in a Presentation
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.
DREAMWEAVER MX 2004 Chapter 3 Working with Tables
Plotting Data with MATLAB
Plotting Multiple Graphs In The Same Plot
MATLAB How to use (using M-files)
Introduction to MATLAB Plotting LAB 3
CSCI N317 Computation for Scientific Applications Unit 1 – 5 MATLAB
Introduction to MATLAB
Plotting Signals in MATLAB
How to Use MATLAB A Brief Introduction.
Introduction to Matlab
Introduction to Excel 2007 Part 3: Bar Graphs and Histograms
Welcome To Microsoft Word 2016
Presentation transcript:

Net 222: Communications and networks fundamentals (Practical Part) Networks and Communication Department Lab 2 : potting to Matlab

Lecture Contents Graph in MatLab 2-D plotting Creating and Type of graph Using Basic Plotting Functions Plotting Multiple graph in same plot Formatting plots Save ,Print ,Close and Export figure Networks and Communication Department

2-D plotting Creating and Type of graph Using Basic Plotting Functions Plotting Multiple graph in same plot Formatting plots Save ,Print ,Close and Export figure Networks and Communication Department

Creating Graph in MATLAB Line Plot Pie Charts, Bar Plots, and Histograms Command Description Plot, plot3 Create 2-D graph and 3-D plotyy 2-D line plots with y-axes on both left and right side loglog Log-log scale plot fplot Plot function between specified limits Command Description bar, bar3 Bar graph 2-D, 3-D Pie, pie3 Pie graph 2-D, 3-D hist Histogram plot Discrete Graph Command Description Stem, stem3 Plot discrete sequence data 2-D, 3-D stairs Stairstep graph Networks and Communication Department

Type of graph Networks and Communication Department

POLTTING IN MATLAB Line plot FUNCTIONs: Plot example: Networks and Communication Department

POLTTING IN MATLAB Plot wit line specification example: Networks and Communication Department

POLTTING IN MATLAB Plotyy ex: Networks and Communication Department

POLTTING IN MATLAB Plot3 3D ex: Networks and Communication Department

Pie Charts, Bar Plots, and Histograms Bar & br3 ex: Networks and Communication Department

Pie Charts, Bar Plots, and Histograms Pie & hist ex: This Matlab code creates a histogram with 3 bars. The first bar has two '1' values, the second bar has three '2' values, and the third bar has one '3' values. y = [1 1 2 2 2 3] hist(y) The horizontal axis has the different values in the vector to be plotted. The vertical axis has the number of those values in the vector. Example 2: This Matlab code generates a histogram of 15 randomly distributed numbers between 0 and 1 (you can type 'help rand' on your command window to learn about random numbers). Note that each column includes a range of values, otherwise the histogram would contain 15 bars. You can type ' help hist ' or ' help bar ' on your command window to see more details of use. Networks and Communication Department

Discrete Graph Stem and stairs ex: Networks and Communication Department

Plotting Functions Networks and Communication Department

2-D Plotting Specify x-data and/or y-data Specify color, line style and marker symbol (Default values used if ‘clm not specified) Syntax: Plotting single line: Plotting multiple lines: plot(xdata, ydata, 'color_linestyle_marker') If data is given, the information is entered as the elements of the vectors x and y. If the values of y are determined by a function from the values of x, than a vector x is created first, and then the values of y are calculated for each value of x. The spacing (difference) between the elements of x must be such that the plotted curve will show the details of the function. The PLOT functions is used to produce 2-dimensional curves, using x- and y-data matrices specified by the user. If not otherwise specified, a blue, solid line, without marker symbols is produced. However, PLOT also accepts character-string arguments that designate various colors, line styles and marker symbols for the resulting line. For example, to produce a red dotted line with square markers at each data point, type: » plot(x, y, 'r:square') You can plot multiple lines at once, using pairs of x- and y-data. As with plotting single lines, the color, line style and marker information can be specified explicitly. However, if not specified, MATLAB automatically cycles through a predefined (but user settable) list of colors to identify each line. For example, the following statement plots three lines as a function of t (First = blue / Second = green / Third = red): » plot(t, y1, t, y2, t, y3) ANOTHER INTERESTING COMMAND: COMET - produces comet-like trajectory of 2-D data points. REF: Color, Line Style, Marker options: For a complete listing of color, line style and marker options see the reference page at the end of this section. plot(x1, y1, 'clm1', x2, y2, 'clm2', ...)

Line Specification Three components can be specified in the string specifiers along with the plotting command. They are: Line style Marker symbol Color Meaning Marker down v circle o triangle left < diamond d triangle right > hexagram h up triangle ^ pentagram p x -mark x plus + point . square s star * Meaning Color Specifiers Blue b Cyan c Green g Black k Magenta m Red r Yellow y Line style Specifiers Meaning '-' Solid line (default) '--' Dashed line ':' Dotted line '-.' Dash-dot line Networks and Communication Department

2-D Plotting - example Create a Blue Sine Wave » x = 0:.1:2*pi; » y = sin(x); » plot(x,y) In this example, the data plotted along the x-axis is defined as: » x=0:0.1:2*pi; The data plotted along the y-axis is defined as: » y=sin(x); Plot these data as follows (default = blue, solid line, no marker): » plot(x,y)

Basic Task: Plot the function sin(x) between 0≤x≤4π Create an x-array of 100 samples between 0 and 4π. Calculate sin(.) of the x-array Plot the y-array >>x=linspace(0,4*pi,100); >>y=sin(x); >>plot(x,y)

Adding a Grid GRID ON creates a grid on the current figure GRID OFF turns off the grid from the current figure GRID toggles the grid state grid on

Controlling the Axes Setting Axis Limits & Grids The axis command lets you to specify your own limits: axis([xmin xmax ymin ymax]) You can use the axis command to make the axes visible or invisible: axis on / axis off The grid command toggles grid lines on and off: grid on / grid off

Using Basic Plotting Functions The following commands are useful when plotting: Note that all text must be put within ' '. Graphing functions MATLAB command Label the horizontal axis. xlabel('text') Label the vertical axis. ylabel('text') Attach a title to the plot. title('text') Change the limits on the x and y axis. axis([xmin xmax ymin ymax]) "Keep plotting in the same window." hold on Turn off the "keep-plotting-in-the-same-window-command". hold off using the strings to label various curves legend(‘string1’,’string2’,’string3’) Places the string (text) on the plot at coordinate x,y relative to the plot axes. text(x,y,’string’) The title (), xlabel (), and ylabel () commands take a string argument in single quotes in order to label the top of the plot, the x-axis, and the y-axis, respectively. The axis () command takes a 2 or 4 element vector as its argument where the minimum and maximum x values are set or the minimum and maximum x and y values are set. Matlab will probably complain loudly if either xmax or ymax is less than xmin or ymin. The use of the axis () command allows the user to override the default setting that Matlab would otherwise pick. It can be use to look closely at a small window of data which would otherwise be unclear if a lot of points where available. It can be particularly useful when making an interactive plot that needs to resize itself. The legend () command allows us to place a legend on a plot. The legend () command takes as its arguments a list of strings enclosed in single quotes that are the explanatory information you would like displayed next to a short sample of the line and data point display for a given set of data. The order of the strings must correspond to the order of the graphs that were added to the plot. In addition to the string, the legend () command can take a position argument that dictates where the legend is to be placed on the plot. The default is the upper right corner of the plot. The text () command takes three arguments: an x and y location to begin writing a string and the text string that you would like displayed. The string must be enclosed in single quotes. The x and y location must be supplied in the same scale that is being used for the x and y axes. In other words, the location of the text string is relative to the plot. Fixed screen locations do not exist. Networks and Communication Department

Multiple graph Networks and Communication Department

Adding additional plots to a figure PLOTTING MULTIPLE GRAPHS IN THE SAME PLOT Plotting two (or more) graphs in one plot: Using the plot command. 2. Using the hold on, hold off commands. In addition to supplying multiple vector pairs to the plot () command, we can create graphs with multiple plots by using the hold on/hold off commands. Once a plot () command has been issued and hold on specified, all subsequent plot () commands will be plotted on the initial graph. Axis properties will be maintained for subsequent plots. If line specifiers are not specified in the subsequent plots, Matlab will use the default order and colors when drawing additional plots on the graph. To return to the default situation in which each plot () command causes a new plot to be drawn in the graph window, the hold off command must be issued.

Adding additional plots to a figure HOLD ON holds the current plot HOLD OFF releases hold on current plot HOLD toggles the hold state » x = 0:.1:2*pi; y = sin(x); » plot(x,y,'b') » grid on » hold on » plot(x,exp(-x),'r:*') By default, PLOT deletes existing lines and resets all axis properties when a new line is drawn (HOLD OFF). To add lines to an existing plot turn HOLD ON. In this mode, MATLAB does not remove the existing graph but adds new lines to the current plot. If the new data falls outside the range of the original axes, MATLAB will rescale the axes accordingly. When you set HOLD OFF, the default mode is restored - PLOT command erases any existing plots and resets all axis properties before creating new plots. When you call HOLD, by itself, the hold state is toggled NOTE: If you do not want MATLAB to rescale the axes, issue the command >>axis manual before you plot your second set of data.

Subplots Networks and Communication Department

Example Example 1: Plot sin(x) and cos(x) over [0,2π], on the same plot with different colours Method 1: >> x = linspace(0,2*pi,1000); >> y = sin(x); >> z = cos(x); >> hold on; >> plot(x,y,‘b’); >> plot(x,z,‘g’); >> xlabel (‘X values’); >> ylabel (‘Y values’); >> title (‘Sample Plot’); >> legend (‘Y data’,‘Z data’); >> hold off; Networks and Communication Department

Formatting Networks and Communication Department

Engineering H192 Winter 2005 Formatting plots A plot can be formatted to have a required appearance. With formatting you can: Add title to the plot. Add labels to axes. Change range of the axes. Add legend. Add text blocks. Add grid. Instructor notes: Matlab provides us with a host of formatting capabilities so that we can add all of the elements to a plot that make it easy for someone to use. We can format plots either through commands entered in a script/function file or directly from the command window. Lecture 22A

Formatting plots Formatting commands. Engineering H192 Winter 2005 Formatting plots There are two methods to format a plot: Formatting commands. In this method commands, that make changes or additions to the plot, are entered after the plot() command. This can be done in the Command Window, or as part of a program in a script file. Formatting the plot interactively in the Figure Window. In this method the plot is formatted by clicking on the plot and using the menu to make changes or add details. Instructor notes: To reiterate...we can format plots via commands in the Command Window or script/function files. Additionally, plots can be formatted interactively using the icons provided in the Figure Window. In cases where multiple plots are being generated, it is probably most efficient to format them via commands such that Matlab takes care of the individual actions. Given a list of what to do, Matlab will be able to do it much more quickly. Lecture 22A

FORMATTING A PLOT IN THE FIGURE WINDOW Engineering H192 Winter 2005 FORMATTING A PLOT IN THE FIGURE WINDOW Once a figure window is open, the figure can be formatted interactively. Use the insert menu to Use Figure, Axes, and Current Object-Properties in the Edit menu Click here to start the plot edit mode. Instructor notes: It’s faster to format plots via the commands, especially if scripts are being run repeatedly or many plots are needed, however, it is possible to format plots interactively through the figure window. Lecture 22A

Close and Save fig. Networks and Communication Department

Close & Saving Plots You can close all the current plots using ‘close all’ Often you may want to save a plot to include in another document, for example a Word document for a project report. From the figure window, save the plot in a file using the jpeg format. The jpeg format is pretty universal and compatible with MicroSoft Word and Powerpoint applications. It’s easy to do, give it a try.

Saving Figures files extenstion: .fig also you can save .jpeg .tif .bmp .pdf. »plot3d_soln

Printing Figures using the Dialog Box: from Command Line: File Menu / Print... >>printdlg from Command Line: Controlling Page Layout: File Menu / Print Preview >>printpreview print print('argument1','argument2',...) For a complete listing of devices and options, see the online help for the PRINT command.

Exporting Figures Copying to Clipboard: Options: (Edit / Copy Option) Copying: (Edit / Copy Figure)

Exercises Plot sin(x2) on the interval [-5,5]. Networks and Communication Department

Exercises 2. Create three curve on the interval [0,2π] step π/100 .the curve equation y = sin(x), y2 = sin(x-.25), y3 = sin(x- .5);

The End Any Questions ? Networks and Communication Department