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.

Slides:



Advertisements
Similar presentations
Excel Vocabulary.
Advertisements

Math Review with Matlab:
Lecture 5.
Complex Numbers S. Awad, Ph.D. M. Corless, M.S.E.E. E.C.E. Department University of Michigan-Dearborn Math Review with Matlab: Complex Math.
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
Introduction to Matlab
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.
Activity Set 3.2 PREP PPTX Visual Algebra for Teachers.
1 Chapter 4 Curve Plotting with MATLAB MATLAB provides some very powerful features for plotting and labeling curves. These operations can be performed.
Matrix Manipulation and 2D Plotting
DAY 8: MICROSOFT EXCEL – CHAPTER 5 Aliya Farheen February 5, 2015.
Calculus S. Awad, Ph.D. M. Corless, M.S.E.E. D. Cinpinski E.C.E. Department University of Michigan-Dearborn Math Review with Matlab: Taylor’s Series.
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.
MATLAB GRAPHICS 2-D.
MATLAB - Lecture 22A Two Dimensional Plots / Chapter 5 Topics Covered:
EGR106 Week 6 MATLAB FILES Two Dimensional Plots Multiple Plots
Exam #3 Review: Comprehensive Exam Class 14.2 Palm Matlab Book Ch. 1-5.
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.
1 Computing for Todays Lecture 10 Yumei Huo Fall 2006.
Dr. Jie Zou PHY Welcome to PHY 3320 Computational Methods in Physics and Engineering.
EXCEL PART 2. Chart Elements Chart Title Plot Area Data Marker X AxesCategory Name Y axes.
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,
XP New Perspectives on Microsoft Office Excel 2003 Tutorial 4 1 Microsoft Office Excel 2003 Tutorial 4 – Working With Charts and Graphics.
Designing Effective Graphics Using MATLAB The Cain Project in Engineering and Professional Communication ENGINEERING SERIES.
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.
SUNY-New Paltz Computer Simulation Lab Electrical and Computer Engineering Department SUNY – New Paltz “Lecture 5”
ENG College of Engineering Engineering Education Innovation Center 1 2D Plots 1 in MATLAB Topics Covered: 1.Plotting basic 2-D plots The plot()
1 "A picture is worth a thousand words." Graphical representation is useful for: Error detection - you can locate outliers in a dataset, program bugs,
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.
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.
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,
ELG 3120 Lab 2 TAs Wei Zhang Ozgur Ekici (Section A) (Section B)
ENG 1181 College of Engineering Engineering Education Innovation Center MatLab – 2D Plots 2 MATLAB has many built-in functions and commands to create various.
Program design and algorithm development We will consider the design of your own toolbox to be included among the toolboxes already available with your.
Introduction to Engineering MATLAB – 9 Plotting - 2 Agenda Formatting plots.
Excel Part 4 Working with Charts and Graphics. XP Objectives Create an embedded chart Work with chart titles and legends Create and format a pie chart.
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.
MATLAB (Matrix Algebra laboratory), distributed by The MathWorks, is a technical computing environment for high performance numeric computation and.
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.
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)
Lecture 25.
Matrices and Arrays.
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.
Tutorial 2 SEG7550 Introduction to MATLAB II
Plotting Multiple Graphs In The Same Plot
MATLAB How to use (using M-files)
Plotting Signals in MATLAB
Designing Effective Graphics Using MATLAB
How to Use MATLAB A Brief Introduction.
Presentation transcript:

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

MATLAB Graphics: U of M-Dearborn ECE Department Introduction to MATLAB and its Toolboxes 2D Graphics 2 2D Graphics Topics n Creating Two Dimensional Plots Creating Two Dimensional Plots n Creating Multiple Plots Creating Multiple Plots n Using a Legend Box Using a Legend Box n Customizing Axes Customizing Axes n Zoom Command Zoom Command n Adding Text Adding Text n Getting Data from a Graph Getting Data from a Graph n Sub Plotting Sub Plotting n Other 2D Features and Plot Types Other 2D Features and Plot Types n 2D EZPlot 2D EZPlot

MATLAB Graphics: U of M-Dearborn ECE Department Introduction to MATLAB and its Toolboxes 2D Graphics 3 » theta=[0:pi/128:2*pi]'; » y=sin(theta); » plot(theta,y,'b.'); » xlabel('Angle in Radians'); » ylabel('Amplitude'); » title('One Period of a Sine Wave'); Two-Dimensional Plots Plot Command for 2D plots n Sinewave Example: Marker: Point Color: Blue Writes Title of Graph

MATLAB Graphics: U of M-Dearborn ECE Department Introduction to MATLAB and its Toolboxes 2D Graphics 4 To Disable Grid 2-D Grids To Enable Grid » grid on » grid off Grid Toggles

MATLAB Graphics: U of M-Dearborn ECE Department Introduction to MATLAB and its Toolboxes 2D Graphics 5 » theta=[0:pi/32:2*pi]'; » y=cos(theta); » stem(theta,y, 'rx'); » xlabel('Angle in Radians'); » ylabel('Amplitude'); » title('Stem Plot of Cosine Wave'); Color: Red Marker: x Stem Command

MATLAB Graphics: U of M-Dearborn ECE Department Introduction to MATLAB and its Toolboxes 2D Graphics 6 Clearing a Figure n In case a figure already exists, the plot command will clear the current figure window and draws a new plot. To clear a figure use the clf command » clf

MATLAB Graphics: U of M-Dearborn ECE Department Introduction to MATLAB and its Toolboxes 2D Graphics 7 Multiple Plots n Consider the following vector pairs: » x1=[ ] ' ; y1=[ ] ' ; (x1 and x2 have same length) » x2=[ ] ' ; y2=[ ] ' ; (x2 & y2 have same length but may be different from x1 & y1) » x3=[ ] ' ; y3=[ ] ' ; (x3 & y3 have same length but may be different from x1 & y1...) n To plot the 3 plots on the same graph plot(x1,y1,'r',x2,y2,'xb',x3,y3,'k'); n xlabel, ylabel, & title can also be put on the graph

MATLAB Graphics: U of M-Dearborn ECE Department Introduction to MATLAB and its Toolboxes 2D Graphics 8 Figure with Multiple Plots plot(x1,y1,'r',x2,y2,'xb',x3,y3,'k'); r =color: red xb = marker: x color: blue k = color: black

MATLAB Graphics: U of M-Dearborn ECE Department Introduction to MATLAB and its Toolboxes 2D Graphics 9 Plotting Using Hold hold on command to draw multiple plots on same figure n » plot(x1,y1,'r'); n » hold on n » plot(x2,y2,'xb') n » hold on n » plot(x3,y3,'k');

MATLAB Graphics: U of M-Dearborn ECE Department Introduction to MATLAB and its Toolboxes 2D Graphics 10 n If x1, x2, & x3 are the same vector x: » x =[ ]’; n And there are y1, y2, & y3 of same size: » y1=[ ]’; » y2=[ ]’; » y3=[ ]’; n Then to plot the 3 plots at the same time » y = [ y1, y2, y3] % 3 columns » plot( x,y ); Vectors of Same Length

MATLAB Graphics: U of M-Dearborn ECE Department Introduction to MATLAB and its Toolboxes 2D Graphics 11 Same Length Plots n 3 Vectors n How to Distinguish between plots?

MATLAB Graphics: U of M-Dearborn ECE Department Introduction to MATLAB and its Toolboxes 2D Graphics 12 Legend Box n To create a legend box in the upper right corner of the plot for the previous example: » legend('First', 'Second', 'Third' ); n To move the legend, click and hold the left mouse button near the edge of the legend and drag it to the required place. n To delete the legend, use » legend off

MATLAB Graphics: U of M-Dearborn ECE Department Introduction to MATLAB and its Toolboxes 2D Graphics 13 Placing Legend Box n Click and Drag to place Legend

MATLAB Graphics: U of M-Dearborn ECE Department Introduction to MATLAB and its Toolboxes 2D Graphics 14 Customizing Axes n To set each axis minimums and maximums » axis([ xmin xmax ymin ymax]); n To return to default settings » axis('auto') or » axis auto n Set scaling factors for both axes to be equal » axis equal n To keep MATLAB from altering the proportions of the axes if the view is changed » axis vis3d

MATLAB Graphics: U of M-Dearborn ECE Department Introduction to MATLAB and its Toolboxes 2D Graphics 15 Zoom Command n To expand the sections of a 2-D plot use » zoom on n Click the left mouse button to expand the area by a factor of 2 around the point under the mouse pointer n Each time you click, the plot expands n To return plot to it’s initial state » zoom out n To exit zoom mode » zoom off Note: Turn Legend off before using zoom

MATLAB Graphics: U of M-Dearborn ECE Department Introduction to MATLAB and its Toolboxes 2D Graphics 16 Adding Text to a Graph gtext is used to place text on a graph n It puts the cross-hair that follows the mouse and waits for a click at the desired location » gtext('These are straight lines');

MATLAB Graphics: U of M-Dearborn ECE Department Introduction to MATLAB and its Toolboxes 2D Graphics 17 Getting Data from a Graph n Suppose there is a current plot on the screen and we want to select some points from the graph and return the x & y coordinates To do this use the ginput command Number of Points Selected Y-Coordinate Vector X-Coordinate Vector » [xp, yp] = ginput(3);

MATLAB Graphics: U of M-Dearborn ECE Department Introduction to MATLAB and its Toolboxes 2D Graphics 18 Subplots on Same Figure subplot(m,n,p) breaks the Figure window into an m-by-n matrix of small axes & selects the p-th axes n The p-th axis is numbered left to right along the top row, second row, etc. n Each subplot is a separate graph When a particular subplot is active, it is the only subplot (or axis) that is responsive to axis, xlabel, etc. The other subplots are not affected. n To return to default mode use: » subplot(1,1,1)

MATLAB Graphics: U of M-Dearborn ECE Department Introduction to MATLAB and its Toolboxes 2D Graphics 19 Subplot Example » subplot(2,3,1); » title('plot 1'); » subplot(2,3,2); » title('plot 2'); » subplot(2,3,3); » title('plot 3'); » subplot(2,3,4); » title('plot 4'); » subplot(2,3,5); » title('plot 5'); » subplot(2,3,6); » title('plot 6');

MATLAB Graphics: U of M-Dearborn ECE Department Introduction to MATLAB and its Toolboxes 2D Graphics 20 Other 2-D Features » loglog(x,y); Plots log scale for x & y » semilogx(x,y); X-Axis uses log scale » semilogy(x,y); Y-Axis uses log scale » pie(a,b); Pie Chart (a&b are vectors) » bar(x,y); Bar Graph

MATLAB Graphics: U of M-Dearborn ECE Department Introduction to MATLAB and its Toolboxes 2D Graphics 21 Pie Chart Example » a=[0.5, 1, 1.6, 1.2, 0.8, 2.1]; » pie(a,a==max(a)); Optional logical vector describing a slice or slices to be pulled out of pie chart

MATLAB Graphics: U of M-Dearborn ECE Department Introduction to MATLAB and its Toolboxes 2D Graphics 22 Bar Graph Example » x=[-2.9:0.2:2.9]; » y=exp(-x.*x); » bar(x,y);

MATLAB Graphics: U of M-Dearborn ECE Department Introduction to MATLAB and its Toolboxes 2D Graphics 23 » f='sin(x)'; » xmin=-2*pi;xmax=2*pi; » ezplot(f,[xmin,xmax]); 2-D EZPlot ezplot(f) is used to plot symbolic variables f is a string or symbolic expression representing a mathematical expression involving a single symbolic variable say ‘ x ’;

MATLAB Graphics: U of M-Dearborn ECE Department Introduction to MATLAB and its Toolboxes 2D Graphics 24 EZPlot Sine Example » f='sin(2*x)*exp(-x)';xmin=0;xmax=2*pi; » ezplot(f,[xmin,xmax]);

MATLAB Graphics: U of M-Dearborn ECE Department Introduction to MATLAB and its Toolboxes 2D Graphics 25 EZPlot X 2 Example » ezplot('x^2',[0,5]),grid;

MATLAB Graphics: U of M-Dearborn ECE Department Introduction to MATLAB and its Toolboxes 2D Graphics 26 EZPlot Exponential Example » f='sin(x)*exp(-x)'; » ezplot(f,[0,10]); » grid on; » ylabel('Amplitude');