GRAPHICS AND VISUALISATION WITH MATLAB

Similar documents
Matlab Practice Sessions

Graphics in MATLAB. Responsible teacher: Anatoliy Malyarenko. November 10, Abstract. Basic Plotting Commands

Lab of COMP 406 Introduction of Matlab (II) Graphics and Visualization

3D plot of a surface in Matlab

INTRODUCTION TO MATLAB PLOTTING WITH MATLAB

PROGRAMMING WITH MATLAB WEEK 6

MATLAB Laboratory 09/23/10 Lecture. Chapters 5 and 9: Plotting

INTERNATIONAL EDITION. MATLAB for Engineers. Third Edition. Holly Moore

What is Matlab? A software environment for interactive numerical computations

GRAPHICS AND VISUALISATION WITH MATLAB Part 2

CSE 123. Plots in MATLAB

Logical Subscripting: This kind of subscripting can be done in one step by specifying the logical operation as the subscripting expression.

Mechanical Engineering Department Second Year (2015)

MATLAB Functions and Graphics

Graphics Example a final product:

Dr Richard Greenaway

Classes 7-8 (4 hours). Graphics in Matlab.

FF505/FY505 Computational Science. MATLAB Graphics. Marco Chiarandini

Plotting - Practice session

Basic Graphs. Dmitry Adamskiy 16 November 2011

Introduction to MATLAB

MATLAB Guide to Fibonacci Numbers

Armstrong Atlantic State University Engineering Studies MATLAB Marina 2D Plotting Primer

A Guide to Using Some Basic MATLAB Functions

Contents. Implementing the QR factorization The algebraic eigenvalue problem. Applied Linear Algebra in Geoscience Using MATLAB

UNIVERSITI TEKNIKAL MALAYSIA MELAKA FAKULTI KEJURUTERAAN ELEKTRONIK DAN KEJURUTERAAN KOMPUTER

1 >> Lecture 4 2 >> 3 >> -- Graphics 4 >> Zheng-Liang Lu 184 / 243

Introduction to Matlab

Introduction to MATLAB: Graphics

12 whereas if I terminate the expression with a semicolon, the printed output is suppressed.

W1005 Intro to CS and Programming in MATLAB. Plo9ng & Visualiza?on. Fall 2014 Instructor: Ilia Vovsha. hgp://

Computing Fundamentals Plotting

STAT 391 Handout 1 Making Plots with Matlab Mar 26, 2006

Programming in Mathematics. Mili I. Shah

The Department of Engineering Science The University of Auckland Welcome to ENGGEN 131 Engineering Computation and Software Development

Lecture 6: Plotting in MATLAB

INTRODUCTION TO MATLAB, SIMULINK, AND THE COMMUNICATION TOOLBOX

Math Sciences Computing Center. University ofwashington. September, Fundamentals Making Plots Printing and Saving Graphs...

Matlab Tutorial 1: Working with variables, arrays, and plotting

Department of Chemical Engineering ChE-101: Approaches to Chemical Engineering Problem Solving MATLAB Tutorial Vb

GUI Alternatives. Syntax. Description. MATLAB Function Reference plot. 2-D line plot

Introduction to. The Help System. Variable and Memory Management. Matrices Generation. Interactive Calculations. Vectors and Matrices

MATLAB Tutorial. Mohammad Motamed 1. August 28, generates a 3 3 matrix.

Introduction to MATLAB programming: Fundamentals

Dr. Iyad Jafar. Adapted from the publisher slides

Basic MATLAB Intro III

ENGG1811 Computing for Engineers Week 11 Part C Matlab: 2D and 3D plots

ELEC6021 Research Methods Matlab Session 2

UNIVERSITI TEKNIKAL MALAYSIA MELAKA FAKULTI KEJURUTERAAN ELEKTRONIK DAN KEJURUTERAAN KOMPUTER

Appendix A. Introduction to MATLAB. A.1 What Is MATLAB?

EGR 102 Introduction to Engineering Modeling. Lab 05B Plotting

Introduction to MATLAB Practical 1

NENS 230 Assignment 4: Data Visualization

Plotting using Matlab. Vytautas Astromskas

More on Plots. Dmitry Adamskiy 30 Nov 2011

Lecture 3 for Math 398 Section 952: Graphics in Matlab

Introduction to Matlab

Prof. Manoochehr Shirzaei. RaTlab.asu.edu

Lab 6: Graphical Methods

MATH 2221A Mathematics Laboratory II

Introduction to graphics

Basic Plotting. All plotting commands have similar interface: Most commonly used plotting commands include the following.

Interactive Computing with Matlab. Gerald W. Recktenwald Department of Mechanical Engineering Portland State University

A Brief Introduction to MATLAB

INC151 Electrical Engineering Software Practice. MATLAB Graphics. Dr.Wanchak Lenwari :Control System and Instrumentation Engineering, KMUTT 1

Overview. Lecture 13: Graphics and Visualisation. Graphics & Visualisation 2D plotting. Graphics and visualisation of data in Matlab

Grace days can not be used for this assignment

Introduction to MATLAB LAB 1

MATLAB. Input/Output. CS101 lec

How to learn MATLAB? Some predefined variables

Constraint-based Metabolic Reconstructions & Analysis H. Scott Hinton. Matlab Tutorial. Lesson: Matlab Tutorial

Introduction to MatLab. Introduction to MatLab K. Craig 1

CCNY. BME 2200: BME Biostatistics and Research Methods. Lecture 4: Graphing data with MATLAB

Eng Marine Production Management. Introduction to Matlab

EL2310 Scientific Programming LAB1: MATLAB lab session. Patric Jensfelt

A very brief Matlab introduction

2D LINE PLOTS... 1 The plot() Command... 1 Labeling and Annotating Figures... 5 The subplot() Command... 7 The polarplot() Command...

Nuts & Bolts guide to MATLAB

PyPlot. The plotting library must be imported, and we will assume in these examples an import statement similar to those for numpy and math as

Getting Started with MATLAB

Computational Approach to Materials Science and Engineering

Data and Function Plotting with MATLAB (Linux-10)

Computational Foundations of Cognitive Science. Inverse. Inverse. Inverse Determinant

SGN Introduction to Matlab

Scientific Functions Complex Numbers

DSP Laboratory (EELE 4110) Lab#1 Introduction to Matlab

PyPlot. The plotting library must be imported, and we will assume in these examples an import statement similar to those for numpy and math as

Introduction to Matlab

Introduction to MATLAB

What is MATLAB? It is a high-level programming language. for numerical computations for symbolic computations for scientific visualizations

Graphics is built upon a collection of objects whose properties can be altered to change the appearance of graphs.

EE 301 Signals & Systems I MATLAB Tutorial with Questions

Introduction to Matlab for Engineers

Introduction to GNU-Octave

EE 350. Continuous-Time Linear Systems. Recitation 1. 1

CSE/NEUBEH 528 Homework 0: Introduction to Matlab

interpolation, color, & light Outline HW I Announcements HW II--due today, 5PM HW III on the web later today

Plotting x-y (2D) and x, y, z (3D) graphs

Computer Programming in MATLAB

Introduction to Matlab

Transcription:

GRAPHICS AND VISUALISATION WITH MATLAB UNIVERSITY OF SHEFFIELD CiCS DEPARTMENT Des Ryan & Mike Griffiths September 2017

Topics 2D Graphics 3D Graphics Displaying Bit-Mapped Images

Graphics with Matlab Many 2D and 3D graphics features, Graphics is built upon a collection of objects whose properties can be altered to change the appearance of graphs, Graphs may be drawn by using the lower-level graphics primitives alone but there are usually higher level functions available for most of the common graphics needs.

Figure Window Any graphics command will normally use the current figure window if there is one or open up a new figure window if there is not one already, and will create the plots within that window. It is always possible to open a new graphics window by using the figure command. Figure windows can later be closed by using the close command or cleared by using the clf command. When dealing with multiple figure windows, a better control can be applied by using handles. Example: h1 = figure; plot(y1); h2 = figure; plot(y2) ; hold on ; plot(y3) close (h1) ; clf(h2) ;

Plot control commands Figure : This command creates a new graphics window. Multiple figure windows will happily coexist. Only one of the figures will have the focus for drawing. Hold : Each graph is usually drawn into a clean window, by deleting the current display area. The hold command will over-ride this behaviour and draw the new graph over the existing one. hold on or hold off Subplot : This command will divide the current graphics figure into multiple panels and allow you to draw a different graphs in each panel. Example: subplot(2,2,1) ; plot(y1) subplot(2,2,2) ; plot(y2) subplot(2,2,3) ; plot(y3)

2D Plotting Functions plot ( x/y) plotting. loglog, semilogx and semilogy are variations of the plot command. title : adds title to a plot xlabel, ylabel : add x and y axis labels text, gtext : to add arbitrary text on a graph. grid : adds grid-lines

x/y line plotting ( i.e. 2D plotting ) Let x and y be vectors of equal length plot(x) -----> plots x versus its index. If x is a matrix plots each column as a different series on the same axis. plot(x,y) -----> plots x versus y plot (x,y1,x,y2,x,y3) plot y1,y2 and y3 using the same x axis and with same scaling. plotyy(x,y1,x,y2) plot y1 and y2 against x on same plot but use different scales for each graph.

Plot Example 1 When plot is called with a matrix argument each column is plotted as a separate line graph on the same graph with the index being the common x-axis. Example: t = 0:0.05:2.3*pi; a = sin(t) ; b=cos(t).*exp(-t) ; c= a.*b c = c ; d = [ a, b ] plot ( d ) ; plot (c) ; Experiment with the figure command and subplot command Try labeling the axes and the figure. Note the dot. between cos(t) and *exp(-t) and also in a.*b.

Plot Example 2 Type the following MATLAB commands. clear t = 1:0.1:pi*2 ; % create a uniform vector of numbers from 1 to 2 pi in t. y = sin( t )./ t ; % y contains sin(t) /t z = cos(t).* exp(1.0./ t); % decaying cosine function w = rand( size(t) ) *0.2 ; % uniform random numbers between 0 and 0.2 yy = y + w ; w = rand( size(t) ) *0.5 ; zz = z + w ; plot ( t, yy, t, zz ) ;

Other useful plotting commands bar - draws bar charts: bar (rand(1,10) ) errorbar : plot with error bars fplot: evaluates a function and plots results with automatic sampling to suit the variation. Example: fplot( 'sin(x).*exp(-x/4)',[ 1 10 ] )

Plot commands that are suitable for statistics presentations Bar and area graphs bar, barh bar3, bar3h area Pie charts pie Histograms hist, histc

x/y curve fitting and data statistics Read three columns of data stored in field.dat file in the examples directory. Plot any one of the columns as an x-y plot. Click Tools-> Basic Fitting Experiment with the plot-type, display-residuals and the equation.

Plot Example 3 Plotting data that is read from a file; load field.dat plot( field)

2D and 3D Plotting via primitive objects Line line, plot3 Patch fill, fill3, patch Rectangle rectangle Surface surf, mesh Text text, gtext, title, xlabel, ylabel, zlabel

Practice Session Example use of graphics primitives Investigate the script grprim.m by editing it and run it to see if you get what you expect. Investigate the valentine.m script as above to see how 3D primitives work.

Plotting in 3D Space plot3 command is the 3d version of the plot command which plots lines in 3D space. syntax: plot3( x, y, z) or plot3( x, y, z, linetype ) Where x,y,z are three vectors or Matrices of the same size and linetype has the same meaning as for the plot command.

Pseudocolour Plots pcolor command is the easiest visualisation command which may be used to have a visual feel of the contents of a matrix. It can also be a very useful method of obtaining filled colour contours when used in connection with the shading command. Example : z = peaks ; pcolor(z) ; shading interp

Mesh and Surface Plots The functions mesh and surf display surfaces in three dimensions. If Z is a matrix whose elements define the heights of a surface over an underlying grid then mesh(z) displays a coloured wire-mesh view of that surface. surf(z) also displays the coloured surface but without the mesh lines superimposed on the surface.

Shading Command This command sets the colour shading properties of the surface and patch objects. it can be one of; shading flat : The object has uniform color. shading faceted : Same as flat + with mesh/border lines drawn. shading interp : Color varies on the surface by interpolating from color of each vertex.

contour and contourf commands Syntax: contour(z) contour(z,n) contour(z,v) contourf(z) contourf(z,n) contourf(z,v) where Z is a matrix n is an integer and v is a vector. If n is specified (n) number of contour lines are drawn. If v is specified each element of v indicates the position of the contour level. contour and contourf are identical except that contourf draws filled contours.

Practice Session Plotting in 3D space t = 0:0.2:10*pi; x = sin(t).*exp(-t/30) y =cos(t).*exp(-t/30) plot3( x, y, t ) ; % compare with : plot( x, y );

Practice session (1) Try: z=peaks; h=surf(z); shading interp ; axis off; colormapeditor and see the effects of changing the color palette. (2) Try: z(20:30,30:40)=nan; set(h, ZData,z ) ; and see the effects. (3) Experiment with the view command on this plot.

Saving your results On the figure Click File > Saveas and in the window that opens click on the save as type drop-down menu to select one of many formats. The same can be achieved by the command saveas Example : saveas( h1, mygraph.jpg ) where h1 is the handle of the graphics figure to be saved. Tip: Start your graph by typing h1=figure to be able to access the handle later

Publishing your work Run and study the series of scripts named randwalk1,2 and 3. Using the Publish tab of the editor, publish this code and the results obtained when running it. An important development is live scripting in which scripting is embedded in documentation

Reading and Displaying Images Matlab can read in images written in various formats such as JPEG, PCX, PNG EXAMPLE: moon=imread( newmoon.jpg ) ; image (moon) ;

Reading and displaying Bitmapped images Type the following commands and inspect the contents of X and map. load mandrill image(x) colormap(map) axis off % Remove axis ticks and numbers axis image % Set aspect ratio to obtain square pixels Study the contents of X and map Investigating an image via its color content

THE END