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.

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
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.
Introduction to Engineering MATLAB – 10 Plotting - 3 Agenda Special 2-D Plots fplot command.
Introduction to Excel 2007 Part 2: Bar Graphs and Histograms February 5, 2008.
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.
MATLAB GRAPHICS 2-D.
MATLAB - Lecture 22A Two Dimensional Plots / Chapter 5 Topics Covered:
EGR106 Week 6 MATLAB FILES Two Dimensional Plots Multiple Plots
Introduction to Excel 2007 Part 3: Bar Graphs and Histograms Psych 209.
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()
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.
Graphs Graphs are used to display data. They visually represent relationships between data. All graphs should have a title that identifies the variables.
Sullivan – Fundamentals of Statistics – 2 nd Edition – Chapter 2 Section 1 – Slide 1 of 27 Chapter 2 Section 1 Organizing Qualitative Data.
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.
Matlab Screen  Command Window  type commands  Current Directory  View folders and m-files  Workspace  View program variables  Double click on a.
Numerical Analysis 3D Plots. A numerical method is a technique for computing a numerical approximation of the solution to a mathematical problem.
Recap Chapter 5 “Plotting” Two Dimensional Plots Simple x-y Plots Titles, Labels and Grids Multiple Plots.
2D Plots 2 ENGR 1181 MATLAB 13. Plotting in the Real World 2D plots generated by MATLAB can be used in a variety of fields, including the one shown here,
Polynomials, Curve Fitting and Interpolation. In this chapter will study Polynomials – functions of a special form that arise often in science and engineering.
ENG 1181 College of Engineering Engineering Education Innovation Center MatLab – 2D Plots 2 MATLAB has many built-in functions and commands to create various.
1 Lecture 5 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.
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.
Unit 3 Guided Notes. Box and Whiskers 5 Number Summary Provides a numerical Summary of a set of data The first quartile (Q 1 ) is the median of the data.
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.
Organizing Qualitative Data
ECE 1304 Introduction to Electrical and Computer Engineering
Physics 114: Supplemental
Create a Graph Instructions
Computer Application in Engineering Design
© 2016 Pearson Education, Ltd. All rights reserved.
Plotting Chapter 5.
Lecture 25.
3.2 Picturing Distributions of Data
Statistical Analysis with Excel
Ch3 Graphics Overview of Plotting Editing Plots
Lecture 25: Exploring data
Graphing Data.
Two-Dimensional Plots
MatLab – Palm Chapter 5 2-D & 3-D Plots
MATLAB DENC 2533 ECADD LAB 9.
Net 222: Communications and networks fundamentals (Practical Part)
Net 222: Communications and networks fundamentals (Practical Part)
Statistical Analysis with Excel
Chapter 2 Describing Distributions of Data
Statistical Analysis with Excel
Statistical Tables and Graphs
Lecture 10 2D plotting & curve fitting
Lecture 3 part-2: Organization and Summarization of Data
MATLAB How to use (using M-files) Double click this icon
MATLAB How to use (using M-files) Double click this icon
Tutorial 2 SEG7550 Introduction to MATLAB II
Plotting Multiple Graphs In The Same Plot
MATLAB How to use (using M-files)
Sexual Activity and the Lifespan of Male Fruitflies
CSCI N317 Computation for Scientific Applications Unit 1 – 5 MATLAB
Plotting Signals in MATLAB
Graphing Data.
Organizing Qualitative Data
The Information Content of Receptive Fields
How to Use MATLAB A Brief Introduction.
Introduction to Excel 2007 Part 3: Bar Graphs and Histograms
Presentation transcript:

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 of the plots Matlab is capable of. 2D plot on the left, polar coordinate plot in the middle and 3D plot on the right with colored shading and mesh lines to better display the surface. 2D plot polar plot 3D plot MATLAB - 5

Two Dimensional Plots in MATLAB Topics Covered: Cautions when using different plot functions fplot polar plot histograms subplot Instructor notes: This presentation introduces 2D plotting in Matlab. It focuses on the plot() command for creating simple plots. Plotting is important because often times we can learn a lot more from a visual representation of data than we can from just looking at raw numbers. It also covers formatting of plots such as adding a title or axis label or legend, etc. Instructional Objectives: Use plot() command in MATLAB to create 2-D plots Use formatting commands in MATLAB to create complete well-formatted 2-D plots Use loglog(), semilogx() and semilogy() commands in MATLAB to create log plots MATLAB - 5

fplot(‘function’,limits) THE fplot COMMAND The fplot command can be used to plot a function with the form: y = f(x) fplot(‘function’,limits) The ‘function’ line can only contain one variable name, e.g. a=2;b=-1;c=3; fplot(‘ax^2+bx+c’, [-2,2]) will give an error message as a, b, and c will be considered variables The function fplot produces a smooth plot of a function for a linear plot. Using fplot and then converting one or both axes to log axes will in general not produce a smooth plot, even when the plotted function should be smooth. Instructor notes: For plotting mathematical functions, in addition to the plot () command, we also have the fplot () command. This command is used specifically for plotting functions, hence the “f” at the beginning of the name. The function to be plotted is supplied to fplot () as a string in single quotes. The domain of the function is supplied as a vector that includes mininum and maximum x values. Additionally, limits can be placed on the minimum and maximum y values of the plot, too. It’s important to note that the function being passed to fplot () can contain only one variable because Matlab expects the variable that it sees in the function to be the independent variable. You cannot define a variable to have a specific value prior to the fplot () command and use that variable in the function. Matlab will not be able to distinguish which one represents the domain variable and which one has the constant value since Matlab will have to parse the string and form of the function and at the point of parsing the function is just a string.

polar(theta,r) THE polar COMMAND The polar command can be used to plot a function with coordinates r and Ɵ. polar(theta,r) Theta and r should be equal length arrays, just as with the plot function. Theta must be in radians. The order of the variables is the opposite to the normal math order. Hold on, hold off must be used to place multiple curves on the same graph. The size of the graph (r coordinate scale) is set by the first curve plotted – so plot the largest curve first

Histograms The hist command can be used to create a histogram, but produces a graph with connected columns which can look bad when printed in b/w. The graph can be improved by using hist to organize data and then feeding the results to the bar function which produces nicer results, e.g. Step 1: Given an array y, [n, xout] = hist(y,nbins); will organize the values y into nbins equally spaced bins. The variable n is an array containing the number of occurrences in each bin and xout is an array containing the center location for each bin. Step 2: bar(xout,n) will create a vertical bar chart of the data. The columns will be separated and look much better in b/w. Instructor notes: For plotting mathematical functions, in addition to the plot () command, we also have the fplot () command. This command is used specifically for plotting functions, hence the “f” at the beginning of the name. The function to be plotted is supplied to fplot () as a string in single quotes. The domain of the function is supplied as a vector that includes mininum and maximum x values. Additionally, limits can be placed on the minimum and maximum y values of the plot, too. It’s important to note that the function being passed to fplot () can contain only one variable because Matlab expects the variable that it sees in the function to be the independent variable. You cannot define a variable to have a specific value prior to the fplot () command and use that variable in the function. Matlab will not be able to distinguish which one represents the domain variable and which one has the constant value since Matlab will have to parse the string and form of the function and at the point of parsing the function is just a string.

subplot(n,m,locn) THE subplot COMMAND The subplot command can be used to organize a number of graphs in the same figure window subplot(n,m,locn) Subplot only indicates a location within the figure window to place a graph. The graph should be created following the subplot command. Any valid MATLAB plotting command may be used, e.g. plot, polar, semilogx, fplot, bar, stem, etc. Not all locations in the array of graphs need to be used. Within a figure window, the same values of n and m must be used for all subplot commands. Unfortunately subplot cannot be used as a sophisticated page layout tool. For example, you cannot place two figures at the top of a figure window with subplot(2,2,1) and subplot(2,2,2) and then place one figure at the bottom with subplot(2,1,2). Maybe someday this will work … Instructor notes: For plotting mathematical functions, in addition to the plot () command, we also have the fplot () command. This command is used specifically for plotting functions, hence the “f” at the beginning of the name. The function to be plotted is supplied to fplot () as a string in single quotes. The domain of the function is supplied as a vector that includes mininum and maximum x values. Additionally, limits can be placed on the minimum and maximum y values of the plot, too. It’s important to note that the function being passed to fplot () can contain only one variable because Matlab expects the variable that it sees in the function to be the independent variable. You cannot define a variable to have a specific value prior to the fplot () command and use that variable in the function. Matlab will not be able to distinguish which one represents the domain variable and which one has the constant value since Matlab will have to parse the string and form of the function and at the point of parsing the function is just a string.

PLOTTING MULTIPLE PLOTS ON ONE PAGE subplot(3,2,1) subplot(3,2,2) subplot(3,2,3) subplot(3,2,5) subplot(3,2,4) subplot(3,2,6) For example, the command: subplot(3,2,p) Creates 6 plots arranged in 3 rows and 2 columns. Instructor notes: Here we see how the subplot () command divides the page into different plotting sections. It’s important to note that the first two parameters supplied to the subplot () command must be the same for all of the plots on a given page.

EXAMPLE OF MULTIPLE PLOTS ON ONE PAGE Instructor notes: Here’s an example of multiple plots appearing on one page. The subplot () commands for this page would be of the form subplot (2, 3, p). Each time the subplot () command is used for this page, it would be followed by a, in this example, plot () command that would complete the plot in the section of the page that subplot () had dictated. The script file of the figure above is shown in the next slide.

% Example of using the subplot command. x1=linspace(1,20,100); y1=sin(x1); subplot(2,3,1) plot(x1,y1) axis([0 20 -2 2]) text(2,1.5,'A plot of sin(x)') y2=sin(x1).^2; subplot(2,3,2) plot(x1,y2) text(2,1.5,'A plot of sin^2(x)') y3=sin(x1).^3; (The file continues on the next slide) Creating a vector x1 Calculating y1 Creating the first plot Plotting the first plot Formatting the first plot Calculating y2 Creating the second plot Plotting the second plot Calculating y3 Formatting the second plot Instructor notes: The next two slides contain a script file that lists the commands needed to create the plot on the previous slide. The most important thing to point out is that each subplot () command is followed by a plotting command...in this case either plot () or fplot ()...that is responsible for actually drawing the plot in the section of the page that its corresponding subplot () command has made active. All ancillary plotting commands, such as axis () and text () correspond to the plot that subplot () has made active prior to the plotting commands.

text(2,1.5,'A plot of sin^3(x)') subplot(2,3,4) plot(x1,y3) axis([0 20 -2 2]) text(2,1.5,'A plot of sin^3(x)') subplot(2,3,4) fplot('abs(sin(x))',[0 20 -2 2]) text(1,1.5,'A plot of abs(sin(x))') subplot(2,3,5) fplot('sin(x/2)',[0 20 -2 2]) text(1,1.5,'A plot of sin(x/2)') subplot(2,3,6) fplot('sin(x.^1.4)',[0 20 -2 2]) text(1,1.5,'A plot of sin(x^1^.^2)') Creating the third plot Plotting the third plot Formatting the third plot Creating the fourth plot Plotting the fourth plot Formatting the fourth plot Creating the fifth plot Plotting the fifth plot Formatting the fifth plot Plotting the sixth plot Formatting the sixth plot Creating the sixth plot Instructor notes: