Introduction to Graphing Using MATLAB. Line Graphs  Useful for graphing functions  Useful for displaying data trends over time  Useful for showing.

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

Computation for Physics 計算物理概論
Lecture 5.
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.
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.
Matrix Manipulation and 2D Plotting
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 - Lecture 22A Two Dimensional Plots / Chapter 5 Topics Covered:
Using Excel for Data Analysis in CHM 161 Monique Wilhelm.
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.
Dr. Jie Zou PHY Welcome to PHY 3320 Computational Methods in Physics and Engineering.
Lecture 9 Plotting in 2-D Plotting in 2-D, Plotting Multiple Curves, Plotting with Figures, Plot Settings, Scaling, Legends © 2007 Daniel Valentine. All.
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
HAWKES LEARNING SYSTEMS Students Matter. Success Counts. Copyright © 2013 by Hawkes Learning Systems/Quant Systems, Inc. All rights reserved. Chapter 2.
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()
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Introduction to MATLAB 7 for Engineers Chapter 5 Advanced.
EZplot Training Manual eZplot can be downloaded from After the setup is complete, an eZplot button will appear.
„  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.
COMP 116: Introduction to Scientific Programming Lecture 5: Plotting, Scripts and publishing.
MAE 1202: AEROSPACE PRACTICUM An Introduction to MATLAB: Part 2 Mechanical and Aerospace Engineering Department Florida Institute of Technology Developed.
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.
Lecture 2 - Matlab Introduction CVEN 302 June 5, 2002.
Barbara/Pratik/Yu. Outline Matlab desktop M-files Variables Arrays Plots.
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)
UW CSE 190p Section 7/26, Summer 2012 Dun-Yu Hsiao.
EGR 106 Lecture 6 2-D Plotting Graphical presentation has become the standard method to show technical information. Engineers use plots to analyze, visualize,
EGR 115 Introduction to Computing for Engineers 2D Plotting – Part I Wednesday 17 Sept 2014 EGR 115 Introduction to Computing for Engineers.
Introduction to Matlab  Matlab is a software package for technical computation.  Matlab allows you to solve many numerical problems including - arrays.
1-d Arrays & Plotting.
ELG 3120 Lab 2 TAs Wei Zhang Ozgur Ekici (Section A) (Section B)
Excel Graphing ENGR 1181 Class 5. Why use Excel?  Excel is a powerful spreadsheet program that can be used for: Creating graphical displays of data Performing.
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.
Example 7 U.S. Executions Chapter 1.2 The table gives the number of executions in the United States for selected years from 1984 to (Source: “The.
Graphing in Excel X-Y Scatter Plot SCI 110 CCC Skills Training.
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,
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.
Prof. N. P. Jadhav Presented by. Overview of MATLAB environment MATLAB is an interactive, matrix-based system for scientific and engineering numeric computation.
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.
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 How to use (using M-files)
Introduction to MATLAB Plotting LAB 3
Plotting Signals in MATLAB
Introduction to Matlab
Presentation transcript:

Introduction to Graphing Using MATLAB

Line Graphs  Useful for graphing functions  Useful for displaying data trends over time  Useful for showing how one variable depends on another

Line Graphs The MATLAB command for creating a line graph is plot. General Form: % A single Function plot(x-coordinates, y-coordinates, optional formatting) % Multiple Functions plot(x-values of f 1, y-values of f 1, formatting for f 1, x-values of f 2, y-values of f 2, formatting for f 2, …)

Simple Examples >> plot(3,4,'r*') X-CoordinatesY-CoordinatesFormatting

Simple Examples >> plot([1 3 5],[ ]) X-CoordinatesY-Coordinates (1,10) (3,12) (5,20)

Simple Examples >> plot([1 3 5],[ ],‘rd--')

Simple Examples >> plot([ ],[ ],'m*-','LineWidth',5)

Format Options (color, linestyle, …) At the command prompt, type: >> help plot Scroll up to see this table of options: b blue. point - solid g green o circle : dotted r red x x-mark -. dashdot c cyan + plus -- dashed m magenta * star (none) no line y yellow s square k black d diamond w white v triangle (down)

Graphing Functions >> t = -2:0.01:7; % Generates a vector of 901 t-values from -2 to +7 spaced apart by 0.01 >> t = linspace(-2,7,500); % Generates a vector of 500 t-values evenly spaced from -2 to +7 STARTINCREMENTMAX STARTSTOP Number of Points

Graphing Functions % Plug each t value into the equation to get a vector of y-values >> y = t.^3 – 6*t.^2 + 3*t + 10; >> plot(t,y) Why t.^2? Why t.^3?

Graphing Functions Plots should be labeled and titled. This can be done using MATLAB commands or by using plot tools. Commands: >> xlabel(‘time, t’); ylabel(‘y-values’); >> title('y = t^3-6t^2+3t+10'); grid

Plot Tools Plot Tools is another nice option for editing graphs. Click this icon to open plot tools

Common Errors Increment too large: >> t = -2:1.5:7; >> y = t.^3–6*t.^2+3*t+10; >> plot(t,y) Choosing the x-axis values poorly. Poor choice for range of x-axis: >> t = -2:0.01:100; >> y = t.^3–6*t.^2+3*t+10; >> plot(t,y)

Solving Equations Graphically >> t = 0:0.01:0.5; >> y = 12*(1-exp(-10*t)); >> plot(t,y);xlabel('time');ylabel('Voltage');

Solving Equations Graphically In the Figure Window, Click on Tools then select Data Cursor. Click on graph – move data cursor if needed using arrow keys. To add additional datatips, right click on an existing datatip and select add new datatip. The capacitor reaches 9 volts between t = 0.13 seconds and t = 0.14 seconds. Note: Our precision is limited by the increment chosen for t which was 0.01 seconds in this example.

Multiple Plots on a Single Graph Note: These functions don’t look so great on the same plot. The function t 2 increases so much faster than the square root function it causes the square root function to look pretty flat. >> plot(t,f1,t,f2,t,f3); >> legend('sqrt(t+1)','3t-10','t^2')

Subplot Command subplot(m,n,k) The subplot command splits the figure window into several sub- windows. The first two entries in subplot show how the window is to be split up by specifying number of rows and number of columns. The third entry points to a particular sub-window. subplot(3,2,1)subplot(3,2,2) subplot(3,2,3)subplot(3,2,4) subplot(3,2,5)subplot(3,2,6) Subplot(3,2,4) would divide the plot window into 3 rows and 2 columns allowing for 6 smaller plot windows and would point to the 4 th sub-window as shown in the diagram.

Multiple Plots Using Subplot Repeat the previous example but put each plot in a separate sub-window of the figure using subplot. >> t = 0:0.01:10; >> f1 = sqrt(t+1); f2 = 3*t-10; f3 = t.^2; >> subplot(1,3,1); >> plot(t,f1);title('sqrt(t+1)') >> subplot(1,3,2);plot(t,f2);title('3t-10') >> subplot(1,3,3);plot(t,f3);title('t^2')

Some Useful Commands for Plotting plot(x-coordinates, y-coordinates, formatting) title(‘Insert Desired Title for Plot’) xlabel(‘Insert label for x-axis’) ylabel(‘Insert label for y-axis’) legend(‘Plot1 Label’,’Plot2 Label’, …) grid % Adds a grid close % Closes the current figure window figure % Creates a new figure window subplot(m,n,k) %Subdivides a figure window into m by n subwindows & points to the kth subwindow axis([xmin xmax ymin ymax]) %Set axis scale hold on %Holds current plot on & allows add-ons hold off % Turns off the hold

Your Turn … Try these commands (one at a time) in MATLAB. Explain what each command does. >> t = -4:0.001:4; >> y1 = t.^2; >> plot(t,y1); xlabel(‘t’) >> close >> y2 = (t-1).^2; >> plot(t,y1,t,y2); legend(‘t^2’,’(t-1)^2’); >> close >> subplot(2,1,1);plot(t,y1);title(‘t^2’); >> subplot(2,1,2); plot(t,y2);title(‘(t-1)^2’);

Test Your Understanding