Introduction to M ATLAB Basic Graphics www.opencadd.com.br.

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
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.
Introduction to M ATLAB 2 Graphics Ian Brooks Institute for Climate & Atmospheric Science School of Earth & Environment
Slide deck by Dr. Greg Reese Miami University MATLAB An Introduction With Applications, 5 th Edition Dr. Amos Gilat The Ohio State University Chapter 5.
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.
Microsoft Excel 2010 Chapter 7
MATLAB GRAPHICS 2-D.
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 Jianguo Wang CSSCR September 2009.
An introduction to Plotting in MATLAB Rikard Johansson Department of Biomedical Engineering (IMT) Linköping University
 Insert a picture from a file  Move and delete images  Use the Picture Tools tab  Add styles, effects, and captions to images  Resize photos  Use.
© 2002 ComputerPREP, Inc. All rights reserved. Word 2000: Working with Long Documents.
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.
ENG College of Engineering Engineering Education Innovation Center 1 2D Plots 1 in MATLAB Topics Covered: 1.Plotting basic 2-D plots The plot()
Inspire students to develop ideas & organize thinking
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.
Matlab tutorial course Lesson 5: Loading and writing data, producing visual output
ELG 3120 Signal and System Analysis 1 Introduction to MATLAB TAs Wei Zhang Ozgur Ekici (Section A)(Section B) ELG 3120 Lab Tutorial 1.
Matlab Programming for Engineers Dr. Bashir NOURI Introduction to Matlab Matlab Basics Branching Statements Loops User Defined Functions Additional Data.
MATLAB for Engineers, by Holly Moore. ISBN © 2007 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is.
Creating Graphical User Interfaces (GUI’s) with MATLAB By Jeffrey A. Webb OSU Gateway Coalition Member.
SUNY-New Paltz Computer Simulation Lab Electrical and Computer Engineering Department SUNY – New Paltz “Lecture 9”
Chapter 4 Working with Frames. Align and distribute objects on a page Stack and layer objects Work with graphics frames Work with text frames Chapter.
Return to Outline Copyright © 2011 by Maribeth H. Price 3-1 Labeling and annotation.
Barak Shenhav Early Evolution Course 11 Feb 2001 MATLAB Visualization, Functions & Debugging.
Matlab Screen  Command Window  type commands  Current Directory  View folders and m-files  Workspace  View program variables  Double click on a.
Recap Chapter 5 “Plotting” Two Dimensional Plots Simple x-y Plots Titles, Labels and Grids Multiple Plots.
EGR 106 Lecture 6 2-D Plotting Graphical presentation has become the standard method to show technical information. Engineers use plots to analyze, visualize,
Sept. 26, 2005 Lecture 6 - By Paul Lin 1 CPET 190 Lecture 6 Problem Solving with MATLAB
© 2011 Delmar, Cengage Learning Chapter 4 Working with Frames.
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.
Figures & Axes, Printing & Saving. Outline Announcements –Homework I on web, due Wed. 5PM by –No lecture on Fri. 10/26, rescheduled to Wed. 10/31.
NET 222: COMMUNICATIONS AND NETWORKS FUNDAMENTALS ( NET 222: COMMUNICATIONS AND NETWORKS FUNDAMENTALS (PRACTICAL PART) Lab 2 : potting to Matlab Networks.
More Matlab Graphics and GUI Graphics subplots some useful commands 3D graphics GUI GUI controls The callback property Other essential properties.
Laboratory Exercise # 10 – Microsoft Word Additional Topics Office Productivity Tools 1 Laboratory Exercise # 10 Microsoft Word Additional Topics Objectives:
An Introduction to Programming in Matlab Emily Blumenthal
Figures & Axes, Printing & Saving. Outline Announcements –Homework I on web, due Wed. 5PM by e- mail A word on HWI and cookies What happens when you plot.
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.
BASIC EDITING Word VIEW OPTIONS Read Mode Print Layout Web Outline Draft.
Reading and Writing Image Files
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
MatLab – Palm Chapter 5 2-D & 3-D Plots
Basic editing Word 2016.
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
INTRODUCTION TO MATLAB AM2032 JAYANTA MUKHERJEE.
MATLAB How to use (using M-files) Double click this icon
Plotting Multiple Graphs In The Same Plot
MATLAB How to use (using M-files)
Plotting Signals in MATLAB
Presentation transcript:

Introduction to M ATLAB Basic Graphics

Copyright  by The MathWorks, Inc. Basic Graphics - 2 Introduction to M ATLAB Section Outline 2-D plotting Graph Annotation Subplots & Alternative Axes 3-D plotting Specialized plotting routines Patches & Images Saving & Exporting Figures Introduction to Handle Graphics Ref: Color, Linestyle, Marker options Special characters using LaTeX

Copyright  by The MathWorks, Inc. Basic Graphics - 3 Introduction to M ATLAB 2-D Plotting Specify x-data and/or y-data Specify color, line style and marker symbol (Default values used if ‘clmnot specified) Syntax: Plotting single line: Plotting multiple lines: plot(x1, y1, 'clm1', x2, y2, 'clm2',...) plot(xdata, ydata, 'color_linestyle_marker') Ref: Color, Linestyle, Marker options

Copyright  by The MathWorks, Inc. Basic Graphics - 4 Introduction to M ATLAB 2-D Plotting - example Create a Blue Sine Wave » x = 0:.1:2*pi; » y = sin(x); » plot(x,y) » x = 0:.1:2*pi; » y = sin(x); » plot(x,y) »plot_2d

Copyright  by The MathWorks, Inc. Basic Graphics - 5 Introduction to M ATLAB Adding a Grid GRID ON creates a grid on the current figure GRID OFF turns off the grid from the current figure GRID toggles the grid state »grid on

Copyright  by The MathWorks, Inc. Basic Graphics - 6 Introduction to M ATLAB Adding additional plots to a figure HOLD ON holds the current plot HOLD OFF releases hold on current plot HOLD toggles the hold state »addgraph » x = 0:.1:2*pi; » y = sin(x); » plot(x,y,'b') » grid on » hold on » plot(x,exp(-x),'r:*') » x = 0:.1:2*pi; » y = sin(x); » plot(x,y,'b') » grid on » hold on » plot(x,exp(-x),'r:*')

Copyright  by The MathWorks, Inc. Basic Graphics - 7 Introduction to M ATLAB Controlling viewing area ZOOM ON allows user to select viewing area ZOOM OFF prevents zooming operations ZOOM toggles the zoom state AXIS sets axis range [xmin xmax ymin ymax] » axis([0 2*pi 0 1])

Copyright  by The MathWorks, Inc. Basic Graphics - 8 Introduction to M ATLAB Graph Annotation TITLE TEXT or GTEXT XLABEL YLABEL »annotation LEGEND

Copyright  by The MathWorks, Inc. Basic Graphics - 9 Introduction to M ATLAB Plot Editor »plotedit Right click (Ctrl-LFT): on graphics objects to modify properties Enable Plotting Editing Add Text Add Arrow Add Line Zoom In Zoom Out Rotate 3D [Edit] -> Copy Figure / Options

Copyright  by The MathWorks, Inc. Basic Graphics - 10 Introduction to M ATLAB Using LaTeX in Graph Annotations Font Type (applies inside {} or until changed): \fontname{ } AND \fontsize{ } Appearance (applies inside {} or until removed): \bf boldface \it OR \slitalics OR slanted \rmremove text formatting (normal) Subscript “_” or superscript “^”: Applies to next character or {text in curly braces} Greek letters and Symbols (prefix with “\”): Selected symbols, e.g. '\pi' =  »latex_examp Ref: Special characters using LaTeX

Copyright  by The MathWorks, Inc. Basic Graphics - 11 Introduction to M ATLAB Exercise: 2-D Plotting Create the following graph: fontsize (14) sin(10  t) cos(10  t) Courier New + Bold

Copyright  by The MathWorks, Inc. Basic Graphics - 12 Introduction to M ATLAB Solution: 2-D Plotting » t = 0:0.01:0.5; » plot(t,sin(10*pi*t),'g-*',... t,cos(10*pi*t),'k:o') » title(['\fontsize{14}In-Phase ({\itsolid})',... 'and Quadrature ({\itdotted}) Signals']) » xlabel('\fontname{Courier New}\bfTime (\mus)') » ylabel('{\it''Normalized''} Signals'); » text(0.2, cos(2*pi)+0.1, '\leftarrow----\rightarrow'); » text(0.175, cos(2*pi)+0.2, '^\pi/_2 phase lag'); » axis([ ]); % NOTE: Could have also used GTEXT or PLOTEDIT: % ============================================= % gtext('\leftarrow----\rightarrow'); % gtext('^\pi/_2 phase lag'); » t = 0:0.01:0.5; » plot(t,sin(10*pi*t),'g-*',... t,cos(10*pi*t),'k:o') » title(['\fontsize{14}In-Phase ({\itsolid})',... 'and Quadrature ({\itdotted}) Signals']) » xlabel('\fontname{Courier New}\bfTime (\mus)') » ylabel('{\it''Normalized''} Signals'); » text(0.2, cos(2*pi)+0.1, '\leftarrow----\rightarrow'); » text(0.175, cos(2*pi)+0.2, '^\pi/_2 phase lag'); » axis([ ]); % NOTE: Could have also used GTEXT or PLOTEDIT: % ============================================= % gtext('\leftarrow----\rightarrow'); % gtext('^\pi/_2 phase lag'); »plot2d_soln

Copyright  by The MathWorks, Inc. Basic Graphics - 13 Introduction to M ATLAB Subplots SUBPLOT- display multiple axes in the same figure window » subplot(2,2,1); » plot(1:10) » subplot(2,2,2) » x = 0:.1:2*pi; » plot(x,sin(x)) » subplot(2,2,3) » x = 0:.1:2*pi; » plot(x,exp(-x),’r’) » subplot(2,2,4) » plot(peaks) » subplot(2,2,1); » plot(1:10) » subplot(2,2,2) » x = 0:.1:2*pi; » plot(x,sin(x)) » subplot(2,2,3) » x = 0:.1:2*pi; » plot(x,exp(-x),’r’) » subplot(2,2,4) » plot(peaks) »subplotex subplot(#rows, #cols, index)

Copyright  by The MathWorks, Inc. Basic Graphics - 14 Introduction to M ATLAB Alternative Scales for Axes SEMILOGY log Y linear X PLOTYY 2 sets of linear axes LOGLOG Both axes logarithmic SEMILOGX log X linear Y »other_axes

Copyright  by The MathWorks, Inc. Basic Graphics - 15 Introduction to M ATLAB 3-D Line Plotting Ref: Color, Linestyle, Marker options » z = 0:0.1:40; » x = cos(z); » y = sin(z); » plot3(x,y,z) » z = 0:0.1:40; » x = cos(z); » y = sin(z); » plot3(x,y,z) plot3(xdata, ydata, zdata, 'clm',...) »plot_3d

Copyright  by The MathWorks, Inc. Basic Graphics - 16 Introduction to M ATLAB 3-D Surface Plotting »surf_3d

Copyright  by The MathWorks, Inc. Basic Graphics - 17 Introduction to M ATLAB Exercise: 3-D Plotting Data from a water jet experiment suggests the following non-linear model for the 2-D stress in the cantilever beam’s horizontal plane. where:  = localized planar stress [MPa] x = distance from end of beam [10 -1 m] y = distance from centerline of beam [10 -1 m] For the particular setup used: (x = {0 to 6}, y = {-3 to 3},  =  =  = 1,  = - 0.2) Plot the resulting stress distribution  =  e -  x [sin(  x)*cos(  y)] x

Copyright  by The MathWorks, Inc. Basic Graphics - 18 Introduction to M ATLAB Solution: 3-D Plotting » B = -0.2; » x = 0:0.1:2*pi; » y = -pi/2:0.1:pi/2; » [x,y] = meshgrid(x,y); » z = exp(B*x).*sin(x).*cos(y); » surf(x,y,z) » B = -0.2; » x = 0:0.1:2*pi; » y = -pi/2:0.1:pi/2; » [x,y] = meshgrid(x,y); » z = exp(B*x).*sin(x).*cos(y); » surf(x,y,z) »plot3d_soln

Copyright  by The MathWorks, Inc. Basic Graphics - 19 Introduction to M ATLAB Specialized Plotting Routines »spec_plots

Copyright  by The MathWorks, Inc. Basic Graphics - 20 Introduction to M ATLAB Specialized Plotting Routines (2) »spec_plots2

Copyright  by The MathWorks, Inc. Basic Graphics - 21 Introduction to M ATLAB » a = magic(4) a = » image(a); » map = hsv(16) map = » colormap(map) » a = magic(4) a = » image(a); » map = hsv(16) map = » colormap(map) Images Reduced Memory Requirements: Images represented as UINT8 - 1 byte »imagex Use Row 2 of colormap for pixel (1,2) Row 2

Copyright  by The MathWorks, Inc. Basic Graphics - 22 Introduction to M ATLAB Example: Images » load cape » image(X) » colormap(map) » load cape » image(X) » colormap(map)

Copyright  by The MathWorks, Inc. Basic Graphics - 23 Introduction to M ATLAB Saving Figures 2 files created:.m- text file.mat- binary data file. »plot3d_soln

Copyright  by The MathWorks, Inc. Basic Graphics - 24 Introduction to M ATLAB using the Dialog Box: File Menu / Print... >>printdlg from Command Line: (Switches are optional) Controlling Page Layout: File Menu / Page Position >>pagedlg Printing Figures print -devicetype -options

Copyright  by The MathWorks, Inc. Basic Graphics - 25 Introduction to M ATLAB Printing image to a file: Print Dialog Box: (File / Print...) >>printdlg Command Line: (Switches are optional) Copying to Clipboard: Options:(File / Preferences) Copying:(Edit / Copy Figure) Exporting Figures print -devicetype -options filename

Copyright  by The MathWorks, Inc. Basic Graphics - 26 Introduction to M ATLAB Introduction to Handle Graphics Graphics in MATLAB consist of objects Every graphics objects has a unique handle and a set of properties which define it’s appearance. Objects are arranged in terms of a set hierarchy

Copyright  by The MathWorks, Inc. Basic Graphics - 27 Introduction to M ATLAB Hierarchy of Graphics Objects Root object Figure object UIControl objects UIMenu objects Axes object Figure object Surface object Line objects Text objects UIControl objects UIMenu objects Axes object Figure object

Copyright  by The MathWorks, Inc. Basic Graphics - 28 Introduction to M ATLAB 1. Upon Creation 2. Utility Functions 0- root object handle gcf- current figure handle gca- current axis handle gco- current object handle 3. FINDOBJ Obtaining an Object’s Handle h_obj = findobj(h_parent, 'Property', 'Value',...) h_line = plot(x_data, y_data,...) What is the current object? Last object created OR Last object clicked Default = 0 (root object)

Copyright  by The MathWorks, Inc. Basic Graphics - 29 Introduction to M ATLAB Deleting Objects - DELETE » h = findobj('Color', [0 0 1]) » delete(h) » h = findobj('Color', [0 0 1]) » delete(h) delete(h_object) » addgraph

Copyright  by The MathWorks, Inc. Basic Graphics - 30 Introduction to M ATLAB Modifying Object Properties Using GET & SET Obtaining a list of current properties: Obtaining a list of settable properties: Modifying an object’s properties: get(h_object) set(h_object) set(h_object, 'PropertyName', 'New_Value',...) Ref: HELPDESK - Handle Graphics Objects: \help\techdoc\infotool\hgprop\doc_frame.html

Copyright  by The MathWorks, Inc. Basic Graphics - 31 Introduction to M ATLAB Modifying Object Properties Using the Property Editor Property List: List of properties & current values for selected object »propedit Object Browser: Hierarchical list of graphics objects Property / Value Fields: Selected property & current value (modify here)

Copyright  by The MathWorks, Inc. Basic Graphics - 32 Introduction to M ATLAB Modifying Object Properties Using the RIGHT CLICK

Copyright  by The MathWorks, Inc. Basic Graphics - 33 Introduction to M ATLAB Working with Defaults - setting Most properties have pre-defined 'factory' values (Used whenever property values are not specified.) You can define your own 'default' values to be used for creating new objects. (Put default settings in “startup.m” to apply to whole session) Syntax: set(ancestor,'Default ', ) Use root object (0) to apply to all new objects

Copyright  by The MathWorks, Inc. Basic Graphics - 34 Introduction to M ATLAB » set(0, 'DefaultSurfaceEdgeColor', 'b') » h=surf(peaks(15)); » set(0, 'DefaultSurfaceEdgeColor', 'b') » h=surf(peaks(15)); Set the Default Surface EdgeColor to Blue & create new surface. » set(h, 'EdgeColor', 'g') Green Set the EdgeColor to Green » set(h, 'EdgeColor', 'default') specifies Default value Reset back to Default Value » set(h, 'EdgeColor', 'factory') specifies Factory value Reset back to Factory Value Example: Working with Defaults »defaults

Copyright  by The MathWorks, Inc. Basic Graphics - 35 Introduction to M ATLAB Return Default Property Value to Factory Setting: Create a new surface: Working with Defaults - removing » set(gcf, 'DefaultSurfaceEdgeColor', 'factory') » set(gcf, 'DefaultSurfaceEdgeColor', 'remove') » h = surf(peaks(15)); »defaults OR