Session III Plotting in MATLAB Rajeev Madazhy Dept of Mechanical Engineering LSU MATLAB Tutorials.

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
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.
Introduction to Engineering MATLAB – 10 Plotting - 3 Agenda Special 2-D Plots fplot command.
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.
By Hrishikesh Gadre Session II Department of Mechanical Engineering Louisiana State University Engineering Equation Solver Tutorials.
MATLAB - Lecture 22A Two Dimensional Plots / Chapter 5 Topics Covered:
EGR106 Week 6 MATLAB FILES Two Dimensional Plots Multiple Plots
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 for Engineers, Third Edition Chapter 5 Advanced Plotting PowerPoint to accompany Copyright © The McGraw-Hill Companies, Inc.
Introduction to Matlab 332:202 Discrete Mathematics Spring 2007.
Plotting - Advanced. FPLOT Plots a function f(x) written as a string within quotation marks. The free variable needs to be designated with x. The lower.
Matlab intro The Environment
Designing Effective Graphics Using MATLAB The Cain Project in Engineering and Professional Communication ENGINEERING SERIES.
 1999 BG Mobasseri1 8/29/2015 MATLAB GRAPHICS - PART II ADVANCED PLOTTING June 4, ‘99.
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”
6.094 Introduction to programming in MATLAB
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.
1 Advanced Plotting ผศ. ดร. อนันต์ ผลเพิ่ม Anan Phonphoem
MATLAB Tutorials Session I Introduction to MATLAB Rajeev Madazhy Dept of Mechanical Engineering LSU.
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,
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.
Department of Mechanical Engineering, LSU Session IV MATLAB Tutorials Session IV Mathematical Applications using MATLAB Rajeev Madazhy
The Hong Kong Polytechnic University Industrial Centre 1 MatLAB Lesson 4 : Polynomial Edward Cheung Room W311g 2008.
MATLAB for Engineers, by Holly Moore. ISBN © 2007 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is.
Computational Methods of Scientific Programming Lecturers Thomas A Herring, Room A, Chris Hill, Room ,
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Introduction to MATLAB 7 for Engineers Chapter 5 Advanced.
Designing Effective Graphics Using MATLAB The Cain Project in Engineering and Professional Communication Linda Driskill, Gang Cheng,
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.
Master in Optical Fiber Communications and Photonic Technologies Foundations of Digital Transmission - Fall quarter Introduction to Matlab.
Mathematical Applications using MATLAB (Cont….)
Matlab Screen  Command Window  type commands  Current Directory  View folders and m-files  Workspace  View program variables  Double click on a.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Introduction to MATLAB 7 for Engineers Chapter 5 Advanced.
Recap Chapter 5 “Plotting” Two Dimensional Plots Simple x-y Plots Titles, Labels and Grids Multiple Plots.
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,
Introduction to Matlab  Matlab is a software package for technical computation.  Matlab allows you to solve many numerical problems including - arrays.
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.
GRAPHICS AND VISUALISATION WITH MATLAB UNIVERSITY OF SHEFFIELD CiCS DEPARTMENT Deniz Savas & Mike Griffiths May 2015.
Introduction to Engineering MATLAB – 9 Plotting - 2 Agenda Formatting plots.
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 =
How to use MATLAB (using M-files) Double click this icon To start Matlab 6.5.
John Federici NJIT Physics Department
Plots and Graphics.
3D-Graphs A 3D surface is defined as: z = f(x, y)
Lecture 25.
Two-Dimensional Plots
MatLab – Palm Chapter 5 2-D & 3-D Plots
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)
CSCI N317 Computation for Scientific Applications Unit 1 – 5 MATLAB
Plotting Signals in MATLAB
How to Use MATLAB A Brief Introduction.
Presentation transcript:

Session III Plotting in MATLAB Rajeev Madazhy Dept of Mechanical Engineering LSU MATLAB Tutorials

Last Session….  MATLAB programming environment  Creating an M-file  Writing programs in M-file  Control Structures in MATLAB  Condition Loops…  Examples, examples, examples….. Department of Mechanical Engineering, LSU Session III

Session III Outline…. Plotting in MATLAB  2-D Graphics  3-D Graphics  Mesh, surface and contour plots in 3-D plots  Exercises in Graphics Department of Mechanical Engineering, LSU Session III

2D Graphics….  x=linspace(0,2*pi,40);  linspace Linearly spaced vector  linspace(x1, x2, N) generates N points  between x1 and x2  It is equivalent to x=(0:2*pi/40:2*pi)  y=sin(x)  plot(x,y) Department of Mechanical Engineering, LSU Session III

In MATLAB…. Department of Mechanical Engineering, LSU Session III

Adding a plot on the same plot….  x=linspace(0,2*pi,40);  y=sin(x);  z=cos(x);  plot(x,y,x,z) Department of Mechanical Engineering, LSU Session III

In MATLAB…. Department of Mechanical Engineering, LSU Session III

Changing Linestyles, Markers, and Colors….  x=linspace(0,2*pi,40);  y=sin(x);  z=cos(x);  plot(x,y,'gx',x,z,'ro') Department of Mechanical Engineering, LSU Session III

In MATLAB…. Department of Mechanical Engineering, LSU Session III

Linestyles, Markers, and Colors…. Symbol ColorSymbolLinestyle yyellow.Point mmagentaocircle ccyanxx-mark rred+plus ggreen*star bblue-solid line wwhite:dotted line kblack-.dash-dot line --dash-dash line Department of Mechanical Engineering, LSU Session III

Adding grids and Labels…. x=linspace(0,2*pi,40); y=sin(x); z=cos(x); plot(x,y,x,z) gridxlabel('Variable X') ylabel('Variable Y and Z') title('Sine and Cosine') Department of Mechanical Engineering, LSU Session III

Adding Text to the plot…. text(2.5,0.7,'sin(x)') %Adding text to the specific %location gtext('cos(x)') %Adding text to the location %you select with a mouse click Department of Mechanical Engineering, LSU Session III

In MATLAB…. Department of Mechanical Engineering, LSU Session III

Adding Legend…. legend('sin','cos') %This command line adds legend %to the plot. The order of %‘string1’,’string2’ should be %the same as it appears in the %plot(x,y,x,z) command line Department of Mechanical Engineering, LSU Session III

In MATLAB…. Department of Mechanical Engineering, LSU Session III

Using hold command…. x=linspace(0,2*pi,40); y=sin(x); plot(x,y) hold on grid z=cos(x); plot(x,z) hold off Department of Mechanical Engineering, LSU Session III

Other useful commands…. loglog: just as plot gives linear coordinate system, loglog gives log-log scale system semilogx: semilog scale plot, x-axis logarithmic semilogy: semilog scale plot, y-axis logarithmic axis([xmin xmax ymin ymax]): set the maximum and minimum values of the axes using values given in the row vector Department of Mechanical Engineering, LSU Session III

Using subplot command…. x=linspace(0,2*pi,40); y=sin(x); z=cos(x); a=sin(2*x); b=sin(4*x); subplot(2,2,1) plot(x,y),axis([0 2*pi -1 1]),title('sin(x)') subplot(2,2,2) plot(x,z),axis([0 2*pi -1 1]),title('cos(x)') subplot(2,2,3) plot(x,a),axis([0 2*pi -1 1]),title('sin(2x)') subplot(2,2,4) plot(x,b),axis([0 2*pi -1 1]),title('sin(4x)') Department of Mechanical Engineering, LSU Session III

In MATLAB…. Department of Mechanical Engineering, LSU Session III

3D Graphics…. The plot command from the 2-D graphics can be extended into 3-D graphics. For example, command plot3 works the same way as plot except plot3 requires three arguments. t=0:pi/50:10*pi; plot3(sin(t),cos(t),t); Department of Mechanical Engineering, LSU Session III

In MATLAB…. Department of Mechanical Engineering, LSU Session III

Mesh, Surface and Contour plots…. x=-7.5:0.5:7.5; y=x; [X,Y]=meshgrid(x,y); R=sqrt(X.^2+Y.^2)+eps; Z=sin(R)./R; mesh(X,Y,Z) Then change the last line to surf(X,Y,Z) and contour3(X,Y,Z,20)respectively Department of Mechanical Engineering, LSU Session III

In MATLAB…. Department of Mechanical Engineering, LSU Session III

In MATLAB…. Department of Mechanical Engineering, LSU Session III

In MATLAB…. Department of Mechanical Engineering, LSU Session III

Other 3D plotting features…. x=-7.5:0.5:7.5; y=x; [X,Y]=meshgrid(x,y); R=sqrt(X.^2+Y.^2)+eps; Z=sin(R)./R; colormap(gray) surfl(X,Y,Z) shading interp axis off Department of Mechanical Engineering, LSU Session III

In MATLAB…. Department of Mechanical Engineering, LSU Session III

Exercise…. The function sphere2 on the next slide is an example to draw a sphere at given position The surface points of the sphere is generated by x=x0+cos(phi)cos(theta) y=y0+cos(phi)sin(theta) z=z0+sin(phi) axis equal sets the aspect ratio so that equal tick mark increments on the x-,y- and z-axis are equal in size Department of Mechanical Engineering, LSU Session III

function sphere2(x0,y0,z0) % Draw a sphere at position (x0,y0,z0) theta=pi*(-1:0.02:1); phi=(pi/2)*(-1:0.02:1)'; x=x0+cos(phi)*cos(theta); y=y0+cos(phi)*sin(theta); z=z0+sin(phi)*ones(size(theta)); surfl(x,y,z); colormap(gray) shading interp axis equal axis ([ ]) axis off MATLAB Code…. Department of Mechanical Engineering, LSU Session III

Plot…. Department of Mechanical Engineering, LSU Session III

Exercise 2 We have two sets of measurement results…. Time(sec)Output(mv) Case 1Case The results are saved in a text format file named result.dat Write a Matlab program to read the results and create a 2-D plot as shown in next slide Department of Mechanical Engineering, LSU Session III

Use Notepad to input the table in the format Save it as result.dat Matlab Code… fn=fopen('result.dat','r'); a=fscanf(fn,'%d%f%f\n',[3,7]); fclose(fn); x=a(1,:); y=a(2,:); z=a(3,:); Writing the code…. Department of Mechanical Engineering, LSU Session III

Plot output…. Department of Mechanical Engineering, LSU Session III

Recap…. Plotting in MATLAB  2-D Graphics  3-D Graphics  Mesh, surface and contour plots in 3-D plots  Exercises in Graphics

Next Session…. Mathematical Applications using MATLAB….  Using fplot function  Minimization  Zero finding  Curve fitting  Interpolation  Integration

Thank You