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.

Slides:



Advertisements
Similar presentations
Lecture 5.
Advertisements

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.
ENGR-25_Plot_Model-2.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical.
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.
Matrix Manipulation and 2D Plotting
Introduction to MATLAB for Biomedical Engineering BME 1008 Introduction to Biomedical Engineering FIU, Spring 2015 Lesson 2: Element-wise vs. matrix operations.
1. Overview 2. plot in 2D 3. Plot in 3D 4. Other possible charts 5. Engineers: label your plots! 6. Plots & Polynomial Plotting 11.
Digital Image Processing Lecture11: Histogram Processing.
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.
Lesson 6: basic plots. Lesson 6 Outline: Plot 1-basic plot commands 1) Figure Line style Marker style Labels and Titles Axes Matlab help LineSpec (colors,
EGR106 Week 6 MATLAB FILES Two Dimensional Plots Multiple Plots
Exam #3 Review: Comprehensive Exam Class 14.2 Palm Matlab Book Ch. 1-5.
Chapter 2 MATLAB Fundamentals.
Vectors and Plotting Selim Aksoy Bilkent University Department of Computer Engineering
An Introduction to MATLAB Magali Billen U C Davis, Geology Department.
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.
EPSII 59:006 Spring Outline Managing Your Session File Usage  Saving Workspace  Loading Data Files  Creating M-files More on Matrices Review.
Designing Effective Graphics Using MATLAB The Cain Project in Engineering and Professional Communication ENGINEERING SERIES.
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.
EZplot Training Manual eZplot can be downloaded from After the setup is complete, an eZplot button will appear.
Matlab Training Sessions 6,7: Plotting. Course Outline Weeks: 1.Introduction to Matlab and its Interface (Jan ) 2.Fundamentals (Operators) 3.Fundamentals.
CMPS 1371 Introduction to Computing for Engineers 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.
MATLAB for Engineers, by Holly Moore. ISBN © 2007 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is.
Designing Effective Graphics Using MATLAB The Cain Project in Engineering and Professional Communication Linda Driskill, Gang Cheng,
Barak Shenhav Early Evolution Course 11 Feb 2001 MATLAB Visualization, Functions & Debugging.
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,
1. Overview 2. plot in 2D 3. Plot in 3D 4. Other possible charts 5. Engineers: label your plots! 6. Plots & Polynomial Plotting 11.
EGR 115 Introduction to Computing for Engineers 2D Plotting – Part I Wednesday 17 Sept 2014 EGR 115 Introduction to Computing for Engineers.
ELG 3120 Lab 2 TAs Wei Zhang Ozgur Ekici (Section A) (Section B)
GRAPHICS AND VISUALISATION WITH MATLAB UNIVERSITY OF SHEFFIELD CiCS DEPARTMENT Deniz Savas & Mike Griffiths May 2015.
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.
Plotting. 2 Initializing Vectors colon operator x = 1:2:10 x = y = 0:0.1:0.5 y =
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.
Session III Plotting in MATLAB Rajeev Madazhy Dept of Mechanical Engineering LSU MATLAB Tutorials.
Plotting Chapter 5.
3D-Graphs A 3D surface is defined as: z = f(x, y)
Lecture 25: Exploring data
Matrices and Arrays.
MatLab – Palm Chapter 5 2-D & 3-D Plots
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.
MATLAB How to use (using M-files)
Advanced Plotting Techniques
Introduction to MATLAB Plotting LAB 3
Yang-Ming University, Taipei, Taiwan
Plotting Signals in MATLAB
How to Use MATLAB A Brief Introduction.
Presentation transcript:

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 the expression fun(x) over the default domain -2pi < x < 2pi. ezplot(fun,[min,max]) plots fun(x) over the domain: min < x < max. ezplot(fun2) plots fun2(x,y)= 0 over the default domain -2pi < x <2pi, -2pi < y < 2pi.

Example: >>ezplot('x^3-2*x') >> ezplot('x^3-x',[-5 5])

>> ezplot('x^2-y^4‘[-5,5,-4,4])

plot command: Linear 2-D plot Syntax: plot (X,Y,linespec, ‘PropertyName',PropertyValue, …) LineWidth - specifies the width (in points) of the line. MarkerEdgeColor - specifies the color of the marker or the edge color for filled markers (circle, square, diamond, pentagram, hexagram, and the four triangles). MarkerFaceColor - specifies the color of the face of filled markers. MarkerSize - specifies the size of the marker in units of points.

Examples: x=1:50; y=sin(x*pi/10)+cos(x*pi/10); plot(x,y) plot(x,y,'--ro') Examples:

Example plot(x,y,'-kd', 'MarkerEdgeColor',‘g', 'MarkerFaceColor', ‘r' ) plot(x,y,'-k', 'Linewidth', 5 ) Example

Plotting multiple plots on the same figure x=1:50; y1=cos(x*pi/10); y2=sin(x*pi/10); plot(x,y1,x,y2) x=1:50; y1=cos(x*pi/10); y2=sin(x*pi/10); plot(x,y1) hold on plot(x,y2)

Plotting multiple plots on the same figure plot(x,y1,’k’,x,y2,’r’) x=1:50; y1=cos(x*pi/10); y2=sin(x*pi/10); plot(x,y1,’k’) hold on plot(x,y2,’r’ )

Editing plots with editplot Syntax plotedit on plotedit off

2 plots: one above the other = 2-by-1 matrix 4 plots: in a 2x2 array = 2-by-2 matrix subplot command Syntax: subplot (N,M,i) Notes: *This function does NOT create a plot *It HAS to be used BEFORE the plot function !!!! N= number of rows M= number of columns i= current plot number Subplot(2,1,1) Subplot(2,1,2) (2,2,1)(2,2,2) (2,2,3)(2,2,4)

Plotting multiple plots on the same figure x=1:50; y1=cos(x*pi/10); y2=1000*y1; plot(x,y1,x,y2,’k’); grid on subplot(2,1,1) plot(x,y1); grid on subplot(2,1,2) plot(x,y2,’k’); grid on

Plot features: xlabel, ylabel, title, grid x=1:50; y1=cos(x*pi/10); y2=sin(x*pi/10); plot(x,y1,x,y2) xlabel(‘x’); ylabel(‘y’); title(‘Example’) grid on text(15,0.8,’y1’) text(20,-0.2,’y2’) Plot features: text and legend legend(‘y1’,’y2’)

plotyy 2-D line plots with y-axes on both left and right side Syntax plotyy(X1,Y1,X2,Y2) plotyy(X1,Y1,X2,Y2) plots X1 versus Y1 with y-axis labeling on the left and plots X2 versus Y2 with y-axis labeling on the right.

Example: >>x=0:0.05:5; y=sin(x.^2); z=cos(x.^2); plotyy(x,y,x,z)

% Line Plot of a Chirp x=0:0.05:5; y=sin(x.^2); plot(x,y); >> % Bar Plot of a Bell Shaped Curve x = -2.9:0.2:2.9; bar(x,exp(-x.*x)); >> % Bar Plot of a Bell Shaped Curve x = -2.9:0.2:2.9; bar(x,exp(-x.*x)); >> % Stairstep Plot of a Sine Wave x=0:0.25:10; stairs(x,sin(x)); >> % Errorbar Plot x=-2:0.1:2; y=erf(x); e = rand(size(x))/10; errorbar(x,y,e); >> % Polar Plot t=0:.01:2*pi; polar(t,abs(sin(2*t).*cos(2*t))); >> x = 0:0.1:4; y = sin(x.^2).*exp(-x); stem(x,y)

Logarithmic Plots commands semilogx() plots x data on log axis and y on linear axis semilogy() plots y data on log axis and x on linear axis loglog()plots x and y on logarithmic axes

Logarithmic Plots Example: plot y=e 2x >> x=0:0.1:10; >> y=exp(2.*x); >>plot(x,y) >> semilogy(x,y)

Three dimensional plots Three dimensional line plots the simplest form is plot(x,y,z) x,y,z are arrays of equal size containing the locations of data points to plot. Example: x(t)= e -0.2t cos (2t) y(t)= e -0.2t sin(2t) motion of an insect t=0:0.1:10; x=exp(-0.2*t).*cos(2*t); y=exp(-0.2*t).*sin(2*t); plot(x,y) title('\bf 2D plot') xlabel('\bfx') ylabel('\bfy') grid on

Three dimensional plots instead we could plot the variables with plot3() to preserve the time information as well as the 2D position of the object. plot3(x,y,t) t=0:0.1:10; x=exp(-0.2*t).*cos(2*t); y=exp(-0.2*t).*sin(2*t); plot3(x,y,t) title('\bf 3D plot') xlabel('\bfx') ylabel('\bfy') zlabel('\bftime') grid on

Three dimensional plots surface, Mesh and contour plots: such kind of plots represent data that is a function of 2D variables. a user must create three arrays of equal size; Commands: mesh(x,y,z) creates a mesh or wireframe plot where x,y and z are 2D arrays of containing x,y,z values at every point, respectively. surf(x,y,z) creates a surface plot, contour(x,y,z)creates a contour plot, [x,y]=meshgrid(xstart:xinc:xend, ystart:yinc:yend) easily create x and y arrays required for 3D plots to create a 3D plot use meshgrid to create the arrays of x and y values then evaluate the function to plot at each of x,y pairs. finally call the above mentioned functions to create plot.

Three dimensional plots Example: create the mesh plot of the following function over the interval [x,y]=meshgrid(-4:0.1:4); z= exp(-0.5*(x.^2+0.5*(x-y).^2)); mesh(x,y,z);