GRAPHICS AND VISUALISATION WITH MATLAB UNIVERSITY OF SHEFFIELD CiCS DEPARTMENT Deniz Savas & Mike Griffiths May 2015.

Slides:



Advertisements
Similar presentations
MATLAB – A Computational Methods By Rohit Khokher Department of Computer Science, Sharda University, Greater Noida, India MATLAB – A Computational Methods.
Advertisements

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.
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.
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.
MATLAB – What is it? Computing environment / programming language Tool for manipulating matrices Many applications, you just need to get some numbers in.
MATLAB - Basics Centro de Informática Universidade Federal de Pernambuco Aprendizagem de Máquina – IN1102 Arley Ristar –
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 Week 3 17 November Outline Graphics – Basic plotting – Editing plots from GUI – Editing plots from m-file – Advanced plotting commands.
Introduction to Matlab Jianguo Wang CSSCR September 2009.
An introduction to Plotting in MATLAB Rikard Johansson Department of Biomedical Engineering (IMT) Linköping University
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.
C51BR Applications of Spreadsheets 1 Chapter 16 Getting Started Making Charts.
Matlab Training Sessions 6,7: Plotting. Course Outline Weeks: 1.Introduction to Matlab and its Interface (Jan ) 2.Fundamentals (Operators) 3.Fundamentals.
Introduction to Matlab 1. Outline: What is Matlab? Matlab Screen Variables, array, matrix, indexing Operators Plotting Flow Control Using of M-File Writing.
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,
„  1999 BG Mobasseri1 9/18/2015 June 2 GRAPHICS IN MATLAB- PART I BASIC 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.
The Scientific Method Honors Biology Laboratory Skills.
INTRODUCTION TO MATLAB LAB# 01
MATLAB for Engineers, by Holly Moore. ISBN © 2007 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is.
MAE 1202: AEROSPACE PRACTICUM An Introduction to MATLAB: Part 2 Mechanical and Aerospace Engineering Department Florida Institute of Technology Developed.
1 DKT 211 Basic Communication Engineering LAB # 1A : (Lecture 1) Introduction to Matlab  Basic Features  Scientific features  Array Operations  Script.
Barak Shenhav Early Evolution Course 11 Feb 2001 MATLAB Visualization, Functions & Debugging.
Introduction to MATLAB Session 5 Simopekka Vänskä, THL 2010.
Matlab Screen  Command Window  type commands  Current Directory  View folders and m-files  Workspace  View program variables  Double click on a.
MATLAB – PT1 The purpose of this workshop is to get you started and to have fun with MATLAB! Let’s talk a little and decide on what we will be covering.
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,
1. Overview 2. plot in 2D 3. Plot in 3D 4. Other possible charts 5. Engineers: label your plots! 6. Plots & Polynomial Plotting 11.
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.
Program design and algorithm development We will consider the design of your own toolbox to be included among the toolboxes already available with your.
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.
CS100A, Fall 1998, Lecture 201 CS100A, Fall 1998 Lecture 20, Tuesday Nov 10 More Matlab Concepts: plotting (cont.) 2-D arrays Control structures: while,
MAE 421 Matlab review Prof. Mark Glauser Created by: David Marr.
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.
Lecture 17 More Plotting Chapter 12 Matrices. Outline from Chapter D Plotting 11.4 Surface Plots 11.5 Interacting with Plotted Data.
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.
Plotting Chapter 5.
3D-Graphs A 3D surface is defined as: z = f(x, y)
Lecture 25.
Ch3 Graphics Overview of Plotting Editing Plots
Lecture 25: Exploring data
Matrices and Arrays.
MATLAB DENC 2533 ECADD LAB 9.
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
Designing Effective Graphics Using MATLAB
Presentation transcript:

GRAPHICS AND VISUALISATION WITH MATLAB UNIVERSITY OF SHEFFIELD CiCS DEPARTMENT Deniz Savas & Mike Griffiths May 2015

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.1:2*pi; a = [ sin(t) ; cos(t).*exp(-t) ] ; a = a‘ ; plot(a) Note the dot. between cos(t) and *exp(-t)

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

Plot Example 3 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 ) ;

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. Click Tools-> Basic Statistics – Save the statistics to the workspace and access them

Properties of a Graphs Investigate the tools menu of the figure window. Line, Text and Axis Properties. Add a graph label and axis labels. Add an arrow pointing to the root and title it. Use File-Property Editor to change y axis to logarithmic Scaling.

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

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.

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 );

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) contourf(Z) contour(Z,n) contourf(Z,n) contour(Z,v) 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 (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.

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