Worksheet 5. Matlab Graphics

Similar documents
Plotting. Aaron S. Donahue. Department of Civil and Environmental Engineering and Earth Sciences University of Notre Dame January 28, 2013 CE20140

Contents. An introduction to MATLAB for new and advanced users

MATLAB 2-D Plotting. Matlab has many useful plotting options available! We ll review some of them today.

INTRODUCTION TO MATLAB by. Introduction to Matlab

Applied Linear Algebra in Geoscience Using MATLAB

Plots Publication Format Figures Multiple. 2D Plots. K. Cooper 1. 1 Department of Mathematics. Washington State University.

Chapter 5 Advanced Plotting

Computer Programming ECIV 2303 Chapter 5 Two-Dimensional Plots Instructor: Dr. Talal Skaik Islamic University of Gaza Faculty of Engineering

CSCD 409 Scientific Programming. Module 6: Plotting (Chpt 5)

Outline. 1 File access. 2 Plotting Data. 3 Annotating Plots. 4 Many Data - one Figure. 5 Saving your Figure. 6 Misc. 7 Examples

Chapter 5 Advanced Plotting and Model Building

Two-Dimensional Plots

Plotting in MATLAB. Trevor Spiteri

Making 2D Plots in Matlab

MATLAB - Lecture # 5

Computer Programming: 2D Plots. Asst. Prof. Dr. Yalçın İşler Izmir Katip Celebi University

Two-dimensional Plots

Week 2: Plotting in Matlab APPM 2460

MATLAB: Plots. The plot(x,y) command

Attia, John Okyere. Plotting Commands. Electronics and Circuit Analysis using MATLAB. Ed. John Okyere Attia Boca Raton: CRC Press LLC, 1999

Engineering Department Professionalism: Graphing Standard

Extrema Tutorial. Customizing Graph Presentation. Cohen et al. NP_A395(1983) Oset et al. NP_A454(1986) Rockmore PR_C27(1983) This work

Introduction to MATLAB 7 for Engineers. Add for Chapter 2 Advanced Plotting and Model Building

Graphics. Chapter 3: Matlab graphics. Objectives. Types of plots

Introduction to Matplotlib

Lecture 1: Introduction to Matlab Programming

John Perry. Fall 2009

How to define Graph in HDSME

Study of Analog Phase-Locked Loop (APLL)

MATHEMATICAL FUNCTIONS AND GRAPHS

CS/NEUR125 Brains, Minds, and Machines. Due: Wednesday, February 8

Outline. Drawing the Graph. 1 Homework Review. 2 Introduction. 3 Histograms. 4 Histograms on the TI Assignment

IPython and Matplotlib

The 21 st Century Wireless Classroom Network for AP Calculus

Data Analysis in MATLAB Lab 1: The speed limit of the nervous system (comparative conduction velocity)

2 a Shade one more square to make a pattern with just one line of symmetry.

Plotting Graphs. CSC 121: Computer Science for Statistics. Radford M. Neal, University of Toronto, radford/csc121/

JUNIOR CERTIFICATE 2009 MARKING SCHEME TECHNICAL GRAPHICS HIGHER LEVEL

Appendix C Transporting Figures

Ms. Cavo Graphic Art & Design Illustrator CS3 Notes

Welcome to Corel DESIGNER, a comprehensive vector-based package for technical graphic users and technical illustrators.

Lab #2 First Order RC Circuits Week of 27 January 2015

PASS Sample Size Software. These options specify the characteristics of the lines, labels, and tick marks along the X and Y axes.

Level Curves in Matlab

Plotting Points in 2-dimensions. Graphing 2 variable equations. Stuff About Lines

Step 1: Set up the variables AB Design. Use the top cells to label the variables that will be displayed on the X and Y axes of the graph

Problem Set 1 (Solutions are due Mon )

Volume of Revolution Investigation

Complex Numbers in Electronics

6.1.2: Graphing Quadratic Equations

ECE 2713 Homework Matlab code:

Now we are going to introduce a new horizontal axis that we will call y, so that we have a 3-dimensional coordinate system (x, y, z).

Digital Signal Processing

Engineering Fundamentals and Problem Solving, 6e

AutoCAD LT 2012 Tutorial. Randy H. Shih Oregon Institute of Technology SDC PUBLICATIONS. Schroff Development Corporation

Using Figures - The Basics

AutoCAD Tutorial First Level. 2D Fundamentals. Randy H. Shih SDC. Better Textbooks. Lower Prices.

EE354 Spring 2016 Lab 1: Introduction to Lab Equipment

Lesson 6 2D Sketch Panel Tools

Simulating Rectangles

ECE 2713 Homework 7 DUE: 05/1/2018, 11:59 PM

Electrical & Computer Engineering Technology

Elementary Statistics. Graphing Data

Microsoft Excel: Data Analysis & Graphing. College of Engineering Engineering Education Innovation Center

Key Stage 3 Mathematics. Common entrance revision

Excel Lab 2: Plots of Data Sets

3. Plotting functions and formulas

AutoCAD LT 2009 Tutorial

Purpose. Charts and graphs. create a visual representation of the data. make the spreadsheet information easier to understand.

Creating Nice 2D-Diagrams

GeoGebra. Before we begin. Dynamic Mathematics for Schools

Excel Tool: Plots of Data Sets

Line Graphs. Name: The independent variable is plotted on the x-axis. This axis will be labeled Time (days), and

1 Running the Program

What number is represented by the blocks? Look at each four digit number. What's the value of each highlighted digit?

Sensors and Scatterplots Activity Excel Worksheet

Addendum COLOR PALETTES

COMPUTER AIDED DRAFTING (PRACTICAL) INTRODUCTION

The Formula for Sinusoidal Signals

The Revolve Feature and Assembly Modeling

Do You See What I See?

The Cartesian Coordinate System

Making the most of graph questions

Anna Gresham School of Landscape Design. CAD for Beginners. CAD 3: Using the Drawing Tools and Blocks

Chapter 2 Frequency Distributions and Graphs

ORTHOGRAPHIC PROJECTION

Transform. Processed original image. Processed transformed image. Inverse transform. Figure 2.1: Schema for transform processing

with MultiMedia CD Randy H. Shih Jack Zecher SDC PUBLICATIONS Schroff Development Corporation

BacklightFly Manual.

06/17/02 Page 1 of 12

aspexdraw aspextabs and Draw MST

Signal Processing. Naureen Ghani. December 9, 2017

Fungus Farmers LEAF CUTTING ANTS A C T I V I T Y. Activity Overview. How much leaf do leaf cutter ants chew?

Copyrighted. Material. Copyrighted. Material. Copyrighted. Copyrighted. Material

Describing Data Visually. Describing Data Visually. Describing Data Visually 9/28/12. Applied Statistics in Business & Economics, 4 th edition

Technical Graphics Higher Level

GE U111 HTT&TL, Lab 1: The Speed of Sound in Air, Acoustic Distance Measurement & Basic Concepts in MATLAB

Quasi-static Contact Mechanics Problem

hp calculators HP 50g Working with Polar Plots Plotting on the HP 50g The 2D/3D (PLOT SETUP) Form The Y= Form The WIN Form Examples of polar plots

Color each numeral card. Count the objects in each group. Then color the group of objects the same color as the numeral card that it matches.

Transcription:

Worksheet 5. Matlab Graphics Two dimesional graphics Simple plots can be made like this x=[1.5 2.2 3.1 4.6 5.7 6.3 9.4]; y=[2.3 3.9 4.3 7.2 4.5 6.1 1.1]; plot(x,y) plot can take an additional string argument controlling any or all of the color, point marker or line style. E.g. plot(x,y, r>-. ) Code r g b c m y k w Colour red green blue cyan magenta yellow black white Code Marker o Circle * Asterisk. Point + Plus x Cross s Square d Diamond ˆ Upward triangle v Downward triangle > Right triangle < Left triangle p Five poined star h Six pointed star Code Line style - Solid line -- Dashed line : Dotted line -. Dash-dot line Plot 10 points forming an ellipse with the semi-major axis at 45 to the x- axis. The points should be cyan downwards facing triangles and joined by a red line. Plot will accept additional arguments controlling various aspects of the plot as key,value pairs. Some examples and their default values are given below. Key Default LineWidth 0.5 MarkerSize 6 MarkerEdgeColor auto MarkerFaceColor none FontSize 10 FontAngle normal William Lee william.lee@ul.ie 1

After using the plot command we can issue commands to alter the display xlabel, ylabel and title should be self explanatory (but if not use help xlabel). The axes can be controlled by the following commands Command axis([xmin xmax ymin ymax]) axis auto axis equal axis off axis square axis tight xlim([xmin xmax]) ylim([ymin ymax]) Action Set limits for both axes Automaticaly choose axes limits Eqalise units on x and y axes No axes Axes are square round plot Axes limits same as those of data Set limist of x axis Set limits of y-axis For instance hold off for i=3:2:200 plot(fft(eye(i))); axis equal; axis off; title(sprintf( n=%d,i)) pause(1) end pause(1) waits for one second before displaying the next plot. hold off ensures a new plot is generated each time. (hold on would retain the old plotted data as well as plotting the new data.) sprintf has the same format as fprintf but prints to a string rather than the screen or a file. fft stands for fast fourier transform. Use CTRL-C to cancel the calculation if you get bored before n reaches 200. Plot a circle, and adjust the axes to ensure it appears circular on the screen. Matlab graphics includes a L A TEX interpreter you can use to typeset equations in the axis labels, the title or anywhere in the plot. n=10; m=100; x=1:n; y=zeros(m,1); pvals=linspace(1,10,m); for i=1:m y(i)=norm(x,pvals(i)); end William Lee william.lee@ul.ie 2

plot(pvals,y, LineWidth,2) % Octave does not support latex text objects if exist( OCTAVE_VERSION ) % Running matlab options={ Interpreter, latex, FontSize,18}; ylabel( $\ x \ _p$,options{:}, HorizontalAlignment, right ) xlabel( $p$,options{:}) title([ \slshape Vector $p$-norm, for $x=... [1 2 \ldots int2str(n) ]ˆT$ ],options{:}) s= $$\ x\ _p=\biggl(\sum_{i=1}ˆn x_i ˆp\biggr)ˆ{1/p}$$ ; text(options{:}, String,s, Position,[3 40]) else % Running octave % this part is only here so I can run the script % at home. options={ Interpreter, tex, FontSize,18}; ylabel( x _p,options{:}, HorizontalAlignment, right ); xlabel( p,options{:}); title([ Vector p-norm, for x=... [1 2.. int2str(n) ]ˆT ],options{:}); s= x _p=(\sigma_{i=1}ˆn x_i ˆp)ˆ{1/p} ; text(options{:}, String,s, Position,[3 40]) end Adjust the limits on the previous plot so that the y axis goes down to zero. Plot a graph of your favourite function including axes labels and use the title to explain why it is your favourite. The same figure can include multiple plots using the subplot command. subplot(n,m,p) splits the plotting window into n m array of regions and ensures that the next plot will go into the pth region. subplot(2,2,1), fplot( exp(sqrt(x)*sin(12*x)),[0,2*pi]) subplot(2,2,2), fplot( sin(round(x)),[0,10], -- ) subplot(2,2,3), fplot( cos(30*x)/x,[0.01 1-15 20], -. ) subplot(2,2,4), fplot( [sin(x),cos(2*x),1/(1+x)],[0,5*pi,-1.5,1.5]) fplot plots a function contained in a string. An additional arguement [xmin xmax] or [xmin,xmax,ymin,ymax] controls the axis limits. More complex geometries can be made up by using different mesh patterns. William Lee william.lee@ul.ie 3

x=linspace(0,15,100); subplot(2,2,1), plot(x,sin(x)) subplot(2,2,2), plot(x,round(x)) subplot(2,1,2), plot(x,sin(round(x))) A full list of the matlab 2D plotting functions is given below. Use the help command to learn more about them plot loglog semilogx semilogy plotyy polar fplot ezplot ezpolar fill area bar barh hist pie comet errorbar quiver scatter stairs Simple x-y plot Plot with logarithmic axes Plot with logarithmic x-axis Plot with logarithmic y-axis Plot with y-axes on left and right Plot in polar coordinates Plot a function Easy to use function plotter Easy to use polar plotter Polygon fill Filled area graph Bar graph Horizontal bar graph Histogram Pie chart Animated, comet like, x-y plot Errorbar plot Quiver (vector field) plot Scatter plot Stairstep plot Create four plots in the same window each containing different types of plot. Create three side by side plots in the same window which describe functions which give straight lines when plotted on loglog, semilogx and semilongy graphs. Three dimensional graphics Lines The plot3 command plots a line from x, y and z vectors. t=-5:.005:5; x=(1+t.ˆ2).*sin(20*t); y=(1+t.ˆ2).*cos(20*t); William Lee william.lee@ul.ie 4

z=t; plot3(x,y,z) grid on FS= FontSize ; xlabel( x(t),fs,14) ylabel( y(t),fs,14) zlabel( z(t),fs,14, Rotation,0) title( plot3 example,fs,14) It accepts the same line/point colour/style options as plot. E.g. plot3(x,y,z, r+ ). Create a plot of a double helix. Contours The contour command produces contour plots. x=-2:0.01:2; y=-1:0.01:1; [X,Y]=meshgrid(x,y); Z=sin(3*Y-X.ˆ2+1)+cos(2*Y.ˆ2-2*X); contour(x,y,z,20) % 20 contour levels Meshes and surfaces Mesh plots x=0:0.1:pi; y=x; [X,Y]=meshgrid(x,y); Z=sin(Y.ˆ2+X)-cos(Y-X.ˆ2); subplot(221) mesh(z) subplot(222) meshc(z) subplot(223) mesh(x,y,z) axis([0 pi 0 pi -5 5]) subplot(224) mesh(z) hidden off William Lee william.lee@ul.ie 5

Surface plots subplot(221) surf(z) subplot(222) surfc(z) subplot(223) surf(z), shading flat subplot(224) waterfall(z) Exporting graphics To export a figure as an eps file use the print command print -deps temp.eps The figure can then be included in a L A TEX document. N.B. All the defaults in Matlab are set for screen viewing. To make them suitable for printing you need to make the font and marker sizes bigger and the lines thicker. William Lee william.lee@ul.ie 6