Recap Chapter 5 “Plotting” Two Dimensional Plots Simple x-y Plots Titles, Labels and Grids Multiple Plots.

Slides:



Advertisements
Similar presentations
Introduction to Engineering MATLAB – 11 Plotting - 4 Agenda Multiple curves Multiple plot.
Advertisements

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 Chapter 4 Curve Plotting with MATLAB MATLAB provides some very powerful features for plotting and labeling curves. These operations can be performed.
Copyright © 2010, 2007, 2004 Pearson Education, Inc. All Rights Reserved. Lecture Slides Elementary Statistics Eleventh Edition and the Triola.
1. Overview 2. plot in 2D 3. Plot in 3D 4. Other possible charts 5. Engineers: label your plots! 6. Plots & Polynomial Plotting 11.
Excel Charts – Basic Skills Creating Charts in Excel.
Reading Graphs and Charts are more attractive and easy to understand than tables enable the reader to ‘see’ patterns in the data are easy to use for comparisons.
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.
HCI 530 : Seminar (HCI) Damian Schofield. HCI 530: Seminar (HCI) Transforms –Two Dimensional –Three Dimensional The Graphics Pipeline.
MATLAB GRAPHICS 2-D.
MATLAB - Lecture 22A Two Dimensional Plots / Chapter 5 Topics Covered:
EGR106 Week 6 MATLAB FILES Two Dimensional Plots Multiple Plots
EGR106 Week 4 Two Dimensional Plots Multiple Plots Plot Formatting Homework.
Lecture 9 Plotting in 2-D Plotting in 2-D, Plotting Multiple Curves, Plotting with Figures, Plot Settings, Scaling, Legends © 2007 Daniel Valentine. All.
Using Charts in a Presentation Lesson 6. Software Orientation Charts can help your audience understand relationships among numerical values. The figure.
Introduction to Array The fundamental unit of data in any MATLAB program is the array. 1. An array is a collection of data values organized into rows and.
Introduction to Excel 2007 Part 3: Bar Graphs and Histograms Psych 209.
An introduction to Plotting in MATLAB Rikard Johansson Department of Biomedical Engineering (IMT) Linköping University
Technology Basics Creating Worksheet Formulas. 2 Understand Formulas Equations used to calculate values in cells are called formulas. Formulas consist.
MATLAB Fundamentals.
Designing Effective Graphics Using MATLAB The Cain Project in Engineering and Professional Communication ENGINEERING SERIES.
Chapter 3 Vectors.
For loop Khairul anwar.
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()
CMPS 1371 Introduction to Computing for Engineers PLOTTING.
1 "A picture is worth a thousand words." Graphical representation is useful for: Error detection - you can locate outliers in a dataset, program bugs,
„  1999 BG Mobasseri1 9/18/2015 June 2 GRAPHICS IN MATLAB- PART I BASIC PLOTTING.
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.
CHAPTER 13 Creating a Workbook Part 2. Learning Objectives Work with cells and ranges Work with formulas and functions Preview and print a workbook 2.
Data Presentation & Graphing Introduction to Mechanical Engineering The University of Texas-Pan American College of Science and Engineering.
The Scientific Method Honors Biology Laboratory Skills.
ECE 1304 Introduction to Electrical and Computer Engineering Section 1.1 Introduction to MATLAB.
Matlab Programming for Engineers Dr. Bashir NOURI Introduction to Matlab Matlab Basics Branching Statements Loops User Defined Functions Additional Data.
MATLAB for Engineers, by Holly Moore. ISBN © 2007 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is.
Lecture 10 2D plotting & curve fitting Subplots Other 2-D Plots Other 2-D Plots Curve fitting © 2007 Daniel Valentine. All rights reserved. Published by.
Creating Graphical User Interfaces (GUI’s) with MATLAB By Jeffrey A. Webb OSU Gateway Coalition Member.
Recap Sum and Product Functions Matrix Size Function Variance and Standard Deviation Random Numbers Complex Numbers.
ES 240: Scientific and Engineering Computation. Chapter 2 Chapter 2: MATLAB Fundamentals Uchechukwu Ofoegbu Temple University.
Chapter 11: Block References and Attributes. After completing this Chapter, you will be able to use the following features: Create and insert block references.
1 DKT 211 Basic Communication Engineering LAB # 1A : (Lecture 1) Introduction to Matlab  Basic Features  Scientific features  Array Operations  Script.
Matlab Screen  Command Window  type commands  Current Directory  View folders and m-files  Workspace  View program variables  Double click on a.
Recap Plots with More than one Line Plots of Complex Arrays Line, Color and Mark Style Axis Scaling and Annotating Plots Subplots Polar Plots Logarithmic.
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.
1 Lecture 5 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.
Program design and algorithm development We will consider the design of your own toolbox to be included among the toolboxes already available with your.
ENG College of Engineering Engineering Education Innovation Center 1 2D Plots 2 in MATLAB Topics Covered: 1.More about 2-D plots  Placing multiple.
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.
CS100A, Fall 1998, Lecture 191 CS100A, Fall 1998 Lecture 19, Thursday Nov 05 Matlab Concepts: Matlab arrays Matlab subscripting Matlab plotting.
CS100A, Fall 1998, Lecture 201 CS100A, Fall 1998 Lecture 20, Tuesday Nov 10 More Matlab Concepts: plotting (cont.) 2-D arrays Control structures: while,
Structured Computer Programming EE 201 Introduction to MATLAB 7 for Engineers بسم الله الرحمن الرحيم King Abdulaziz University College of Engineering Dept.
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.
ECE 1304 Introduction to Electrical and Computer Engineering
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.
Plotting Chapter 5.
Lecture 25.
Ch3 Graphics Overview of Plotting Editing Plots
Lecture 25: Exploring data
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)
Plotting Signals in MATLAB
Presentation transcript:

Recap Chapter 5 “Plotting” Two Dimensional Plots Simple x-y Plots Titles, Labels and Grids Multiple Plots

Plots with More than One Line A plot with more than one line can be created in several ways By default, the execution of a second plot statement will erase the first plot However, you can layer plots on top of one another by using the hold on command Execute the following statements to create a plot with both functions plotted on the same graph x = 0:pi/100:2*pi; y1 = cos(x*4); plot(x,y1) y2 = sin(x); hold on; plot(x, y2)

The hold on command can be used to layer plots on same graph

Continued…. Semicolons are optional on both the plot statement and the hold on statement MATLAB will continue to layer the plots until the hold off command is executed: hold off Another way to create a graph with multiple lines is to request both lines in a single plot command MATLAB interprets the input to plot as alternating x and y vectors, as in plot(X1, Y1, X2, Y2) where the variables X1, Y1 form an ordered set of values to be plotted and X2, Y2 form a second ordered set of values.

Continued…. If the plot function is called with a single matrix argument, MATLAB draws a separate line for each column of the matrix The x -axis is labeled with the row index vector, 1: k, where k is the number of rows in the matrix. This produces an evenly spaced plot, sometimes called a line plot If plot is called with two arguments, one a vector and the other a matrix, MATLAB successively plots a line for each row in the matrix For example: we can combine y1 and y2 into a single matrix and plot against x : Y = [y1; y2]; plot(x,Y) This creates the same plot as previous figure, with each line a different color

Continued…. Here’s another more complicated example: X = 0:pi/100:2*pi; Y1 = cos(X)*2; Y2 = cos(X)*3; Y3 = cos(X)*4; Y4 = cos(X)*5; Z = [Y1; Y2; Y3; Y4]; plot(X, Y1, X, Y2, X, Y3, X, Y4) This code produces the same result as plot(X, Z)

Multiple Plots on Same Graph

Continued…. A function of two variables, the peaks function produces sample data that are useful for demonstrating certain graphing functions Calling peaks with a single argument n will create an nxn matrix We can use peaks to demonstrate the power of using a matrix argument in the plot function The command plot(peaks(100)) results in the impressive graph

The peak Function, plotted with single augment in plot Command

Plots of Complex Arrays If the input to the plot command is a single array of complex numbers, MATLAB plots the real component on the x -axis and the imaginary component on the y -axis For example: if A = [0+0i,1+2i, 2+5i, 3+4i] then plot(A) title('Plot of a Single Complex Array') xlabel('Real Component') ylabel('Imaginary Component') returns graph shown in next slide

Continued…. If we attempt to use two arrays of complex numbers in the plot function, the imaginary components are ignored The real portion of the first array is used for the x -values, and the real portion of the second array is used for the y –values To illustrate, first create another array called B by taking the sine of the complex array A : B = sin(A) returns B = i i i and plot(A,B) title('Plot of Two Complex Arrays') xlabel('Real Component of the X array') ylabel('Real Component of the Y array') gives us an error statement. Warning: Imaginary parts of complex X and/or Y arguments ignored The data are still plotted, as shown in figure in next slide

Line, Color and Mark Style The appearance of plots can be changed by selecting user- defined line styles and line colors and by choosing to show the data points on the graph with user specified mark styles The command help plot returns a list of the available options

Continued…. The following commands illustrate the use of line, color, and mark styles: x = [1:10]; y = [58.5, 63.8, 64.2, 67.3, 71.5, 88.3, 90.1, 90.6, 89.5,90.4]; plot(x,y,':ok') The resulting plot (shown in next slide) consists of a dashed line, together with data points marked with circles

Continued…. To specify line, mark, and color styles for multiple lines, add a string containing the choices after each pair of data points If the string is not included, the defaults are used For example: plot(x,y,':ok',x,y*2,'--xr',x,y/2,'-b') results in the graph shown in next slide

Axis Scaling and Annotating Plots MATLAB automatically selects appropriate x -axis and y -axis scaling Sometimes, it is useful for the user to be able to control the scaling Control is accomplished with the axis function Executing the axis function without any input axis freezes the scaling of the plot If you use the hold on command to add a second line to your graph, the scaling cannot change To return control of the scaling to MATLAB, simply re-execute the axis function

Continued…. The axis function also accepts input defining the x -axis and y - axis scaling The argument is a single matrix, with four values representing: The minimum x value shown on the x -axis The maximum x value shown on the x -axis The minimum y value shown on the y -axis The maximum y value shown on the y -axis Thus, the command axis([-2, 3, 0, 10]) fixes the plot axes to x from -2 to +3 and y from 0 to 10

Continued…. It is often useful to create plots where the scaling is the same on the x- and y -axis. This is accomplished with the command axis equal MATLAB offers several additional functions that allow to annotate plots The legend function requires the user to specify a legend in the form of a string for each line plotted, and displays it in the upper right hand corner of the plot The text function allows to add a text box to plot, which is useful for describing features on the graph It requires the user to specify the location of the lower left-hand corner of the box in the plot window as the first two input fields, with a string specifying the contents of the text box in the third input field

Continued…. The use of both legend and text is demonstrated in the following code (modification of last graph) legend('line 1', 'line 2', 'line3') text(1,100,'Label plots with the text command') We added a title, x and y labels, and adjusted the axis with the following commands: xlabel('My x label'), ylabel('My y label') title('Example graph for Chapter 5‘) axis([0,11,0,200]) The results are shown in next slide

Continued…. A function similar to text is gtext, which allows the user to interactively place a text box in an existing plot The gtext function requires a single input, the string to be displayed gtext('This string will display on the graph') Once executed, a crosshair appears on the graph The user positions the crosshair to the appropriate position The text is added to the graph when any key on the keyboard is depressed, or a mouse button is selected

Subplots The subplot command allows to subdivide the graphing window into a grid of m rows and n columns The function subplot(m,n,p) splits the figure into an mxn matrix The variable p identifies the portion of the window where the next plot will be drawn For example: if the command subplot(2,2,1) is used, the window is divided into two rows and two columns, and the plot is drawn in the upper left-hand window

Continued…. The following commands split the graph window into a top plot and a bottom plot: x = 0:pi/20:2*pi; subplot(2,1,1) plot(x,sin(x)) subplot(2,1,2) plot(x,sin(2*x) The first graph is drawn in the top window, since p=1 Then the subplot command is used again to draw the next graph in the bottom window

Polar Plots MATLAB provides plotting capability with polar coordinates: polar(theta, r) generates a polar plot of angle theta (in radians) and radial distance r For example: the code x = 0:pi/100:pi; y = sin(x); polar(x,y) generates the plot in figure in next slide A title was added in the usual way: title('The sine function plotted in polar coordinates is a circle.')

Logarithmic Plots For most plots that we generate, the x - and y -axes are divided into equally spaced intervals; these plots are called linear or rectangular plots Occasionally, however, we may want to use a logarithmic scale on one or both of the axes A logarithmic scale (to the base 10) is convenient when a variable ranges over many orders of magnitude, because the wide range of values can be graphed without compressing the smaller values Logarithmic plots are also useful for representing data that vary exponentially

Continued…. the logarithm of a negative number or of zero does not exist, if data include these values, MATLAB will issue a warning message and will not plot the points in question However, it will generate a plot based on the remaining points Each command for logarithmic plotting can be executed with one argument, as we saw in plot(y) for a linear plot In these cases, the plots are generated with the values of the indices of the vector y used as x values

Example

Bar Graphs and Pie Charts Bar graphs, histograms, and pie charts are popular forms for reporting data

Example clear, clc x = [1,2,5,4,8]; y = [x;1:5]; subplot(2,2,1) bar(x),title('A bar graph of vector x') subplot(2,2,2) bar(y),title('A bar graph of matrix y') subplot(2,2,3) bar3(y),title('A three-dimensional bar graph') subplot(2,2,4) pie(x),title('A pie chart of x')

Histograms A histogram is a special type of graph that is particularly useful for the statistical analysis of data It is a plot showing the distribution of a set of values In MATLAB, the histogram computes the number of values falling into 10 bins that are equally spaced between the minimum and maximum values

Example Define a matrix x as the set of grades from the Introduction to Engineering final, the scores could be represented in a histogram generated with the following code x = [100,95,74,87,22,78,34,35,93,88,86,42,55,48]; hist(x)

Example Continued…. The default number of bins is 10, but if we have a large data set, we may want to divide the data up into more bins For example, to create a histogram with 25 bins, the command would be hist(x, 25) If you set the hist function equal to a variable, as in A = hist(x) the data used in the plot are stored in A : A =

X–Y Graphs with Two Y-Axes

Continued…. The plot of sin( x ) looks like it runs straight along the line x=0, because of the scale The plotyy function allows us to create a graph with two y -axes, the one on the left for the first set of ordered pairs and the one on the right for the second set of ordered pairs: subplot(2,1,2) plotyy(x,y1,x,y2) Titles and labels were added in the usual way The y -axis was not labeled, because the results are dimensionless

Continued…. The plotyy function can create a number of different types of plots by adding a string with the name of the plot type after the second set of ordered pairs The plots(shown in next slide) were created with the following code and have a logarithmically scaled axis: subplot(2,1,1) plotyy(x,y1,x,y2, 'semilogy') subplot(2,1,2) plotyy(x,y1,x,y2,'semilogx')

Continued…. For other problems it may be required to add y -axis labels. The left-hand y -axis is easy—just add the label in the usual way ylabel('Left y-axis label') The right-hand y -axis label is trickier You can add it using MATLAB’s interactive controls, described in a later section, or you can use handle graphics This involves giving the plot a name, and then using the name to switch to the second axis set The code is a = plotyy(x,y1,x,y2) ylabel(a(2),'Right y-axis label')