The Hong Kong Polytechnic University Industrial Centre 1 MatLAB Lesson 3 : Graphics Edward Cheung Room W311g 2008m.

Slides:



Advertisements
Similar presentations
MS-Word XP Lesson 7.
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 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
1. Overview 2. plot in 2D 3. Plot in 3D 4. Other possible charts 5. Engineers: label your plots! 6. Plots & Polynomial Plotting 11.
Fundamental Features of Graphs All graphs have two, clearly-labeled axes that are drawn at a right angle. –The horizontal axis is the abscissa, or X-axis.
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.
FIRST COURSE Excel Tutorial 4 Working with Charts and Graphics.
MATLAB GRAPHICS 2-D.
Lesson 6: basic plots. Lesson 6 Outline: Plot 1-basic plot commands 1) Figure Line style Marker style Labels and Titles Axes Matlab help LineSpec (colors,
MATLAB - Lecture 22A Two Dimensional Plots / Chapter 5 Topics Covered:
EGR106 Week 6 MATLAB FILES Two Dimensional Plots Multiple Plots
Vectors and Plotting Selim Aksoy Bilkent University Department of Computer Engineering
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.
1 Computing for Todays Lecture 10 Yumei Huo Fall 2006.
Lecture 9 Plotting in 2-D Plotting in 2-D, Plotting Multiple Curves, Plotting with Figures, Plot Settings, Scaling, Legends © 2007 Daniel Valentine. All.
XP New Perspectives on Microsoft Office Excel 2003 Tutorial 4 1 Microsoft Office Excel 2003 Tutorial 4 – Working With Charts and Graphics.
An introduction to Plotting in MATLAB Rikard Johansson Department of Biomedical Engineering (IMT) Linköping University
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()
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.
Microsoft Office Illustrated Introductory, Premium Edition with Charts Working.
© 2008 The McGraw-Hill Companies, Inc. All rights reserved. WORD 2007 M I C R O S O F T ® THE PROFESSIONAL APPROACH S E R I E S Lesson 14 Tables.
Microsoft ® Office Excel 2007 Working with Charts.
MATLAB for Engineers, by Holly Moore. ISBN © 2007 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is.
Basic Editing Lesson 2.
Graphs in Physics PowerPoint #4. A graph is… A convenient way to show data.
Recap Sum and Product Functions Matrix Size Function Variance and Standard Deviation Random Numbers Complex Numbers.
CREATING CHARTS By: Dr. Ennis - Cole OBJECTIVES b Identify the elements of an Excel chart b Identify the type of chart represents your data most effectively.
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.
Barak Shenhav Early Evolution Course 11 Feb 2001 MATLAB Visualization, Functions & Debugging.
Written by: Itzik Ben Shabat Technion - Israel Institute of Technology Faculty of Mechanical Engineering Laboratory for CAD & Lifecycle Engineering Lab.
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,
XP New Perspectives on Microsoft Excel 2002 Tutorial 4 1 Microsoft Excel 2002 Tutorial 4 – Working With Charts and Graphs.
1 Lecture 5 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.
1 Excel Lesson 5 Working with Multiple Worksheets and Charts Microsoft Office 2010 Introductory Pasewark & Pasewark.
Introduction to Engineering MATLAB – 9 Plotting - 2 Agenda Formatting plots.
Excel Part 4 Working with Charts and Graphics. XP Objectives Create an embedded chart Work with chart titles and legends Create and format a pie chart.
Excel Part 4 Working with Charts and Graphics. XP Objectives Create an embedded chart Work with chart titles and legends Create and format a pie chart.
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.
Microsoft Office XP Illustrated Introductory, Enhanced With Charts Working.
Plotting. 2 Initializing Vectors colon operator x = 1:2:10 x = y = 0:0.1:0.5 y =
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: Exploring data
Matrices and Arrays.
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
Microsoft Office Illustrated Introductory, Windows XP Edition
MATLAB How to use (using M-files) Double click this icon
Tutorial 2 SEG7550 Introduction to MATLAB II
MATLAB How to use (using M-files)
Plotting Signals in MATLAB
Presentation transcript:

The Hong Kong Polytechnic University Industrial Centre 1 MatLAB Lesson 3 : Graphics Edward Cheung Room W311g 2008m

2 Plotting Graph is more easy to be read then table in particular to grasp the relationships among variables Horizontal axis is a control variable Plots are normally done in two dimensions Plot File Formats .fig MatLab format – double click to open  jpg/bmp/tiff…etc raster image formats for inserting into reports

3 Simple Graph Plot graph >> x=0:5; y=0:10:50; plot(x,y) Always add title & label all axis – Meaning & Unit!!! >> xlabel('time taken (sec)') ylabel('Distance Travelled (m)') title('Speed of Test Vehicle') title(‘Speed of Mark’’s Vehicle’) % note double apostrophe for Mark‘s A new plot() will erase previously defined labels and title

4 Single Variable Plotting >> z=sin(0:0.1:2*pi);plot(z) What is the size of sample? >> size(z) ans = 1 63 % 1 Dimension 63 Elements >> xlabel('t (0.1 radian)'); ylabel('z'); title('Function of z') Note the colour cue when typing (')s - “A hint of warning on typing mistake”

5 Figure Copy Template Setting Menu  File  Preference

6 Plot More Than One Variable on Same Graph % Try example as follows:- x=0:pi/100:2*pi; %set an array x range 2Pi y1=sin(x); % y1 is the first function plot(x,y1) y2=sin(x-pi/4); % y2 is the second function hold on % don’t clear the graph plot(x,y2) % plot second graph y3=sin(x-pi/2); % y3 is the third function pause(5) % wait 5 seconds plot(x,y3) % plot y3 on same graph y4=sin(x-pi); % y4 is the last one pause % wait for pressing key plot(x,y4) % then plot y4 hold off % clear the hold % same colour because ‘hold off’ is used

7 Plot more than one function on a graph % Example (multi-colour plot):- x=-10:10; y=x.^2; plot(x,y,x,2*y,x,3*y,x,4*y) h=findobj(gcf,'linewidth',.5); set(h,'linewidth',2) grid Usage:- Set(h,’property_name’, ‘property_value’) H=gcf % get current figure handle (e.g. H=1) findobj(‘object_handle’,’property_name’,’property _value’)

8 Basic Plotting/Formatting Functions help graphics plot(x,y,’linestyle_marker_colour’) – creates an x-y plot title(‘string’) – add title to a plot xlabel(‘string’) – label x-axis ylabel(‘string’) – label y-axis grid – grid on/off pause – pauses the execution of the program and allow the user to read the graph figure – create/index for graph reference >> figure(2) hold – on/off – freeze the current plot to allow overlaid clf – clear current figure

9 Graph Formating Line style, colours & markers can be specified with the plot(x,y,s) command S is a character string made from one element Usage of line types, plot symbols and colors are given in the help page >> help plot Example >> x=0:0.1:2*pi; y=sin(x); plot(x,y,':sg') % colon=>dotted line Line style, colours & markers are independent parameters and all must be specified for plotting

10 Properties of Graphics >>get(gcf) % return current figure properties >>get(gca) % return current axis properties Linewidth is a scale object  The width of the line object. Specify this value in points (1 point = 1/72 inch). The default LineWidth is 0.5 point. >>set(gca,'linewidth',4) % set line width

11 Marker Properties MarkerSize. The size of the marker, in points.  The default value is 6 pts  The point marker drawn at 1/3 of the specified size MarkerFaceColor. The fill colour for markers that are closed shapes (circle, square, diamond, pentagram, hexagram, and the four triangles).  none = interior of the marker transparent  auto = same colour as the axis MarkerEdgeColor. The colour of the marker or the edge colour for filled markers (circle, square, diamond, pentagram, hexagram, and the four triangles).  none = no colour, which makes non-filled markers invisible  auto = same colour as the line

12 Example on the Properties of Markers x=-pi:pi/10:pi; y=tan(sin(x))-sin(tan(x)); plot(x,y,'--rs','Linewidth',2,... 'MarkerEdgeColor','k','MarkerFaceColor','g','Mark erSize',10)

13 Multiple Plots per Figure Subplot(m,n,i) breaks the figure into an m-by-n matrix of smaller plots and numbered in row to column >> subplot 221 % 2 x 2 plot #1 t=linspace(0,2*pi,4); % t->x axis range 2pi plot(sin(t)) % a poor resolution plot y = linspace(a,b,n) generates a row vector y of n points linearly spaced between and including a and b.  when n is not specified, n=100  function similar to the colon operator For a better resolution set n=100 >> t1=linspace(0,2*pi); subplot 222 plot(sin(t1))

14 Multiple Plots Per Figure (Cont.) Set x axis to radian >> subplot 223 plot(t1,sin(t1)) Suppose we want the data to fill the axes >> subplot 224 plot(t1,sin(t1)) axis tight % set axes limit to data range axis auto/tight/equal/square/off/on  Axes control function >> axis([xmin xmax ymin ymax]) Sets the limit for x & y axes of the current plot

15 Axis Limits Change axes for a zoom in plot x=0:.01:30; subplot(211) plot(x,x.*sin(x)) subplot(212) plot(x,x.*sin(x)) axis([ ])

16 Three Plots In One Graph Example: plotting an underdamped function in 3 views (P.23) >> x=linspace(0,1); y=exp(-x).*cos(6*pi*x); w=exp(-x); z=-w; subplot(2,2,1) plot(x,y) subplot(2,2,2) >> plot(x,w,'r:',x,z,'r:') subplot(2,1,2) plot(x,y,x,w,'r:',x,z,'r:')

17 Multiple Plots per Figure with Window Plot x=0:0.05:2*pi; y=sin(x); subplot(2,1,1) plot(x,y,'r') subplot(2,1,2) plot(x,y,'b') axis off axes('Position', [ ]) plot(x,y,'g')

18 Axes Axes()  Is a function that can be used to create an axes graphics object in the current figure using default property values. The axes Position property enables the user to define the location of the axes within the figure window.  h = axes('Position',position_rectangle)  axes('position', rect) opens up an axis at the specified location  rect= [left, bottom, width, height] specifies the location and size of the side of the axis box, relative to the lower-left corner of the Figure window, in normalized units where (0,0) is the lower-left corner and (1.0,1.0) is the upper-right.

19 Additional Graph Formatting Functions Title(‘string) % discuss already Add legend to a graph >>legend(‘string1’, ‘string2’,…) >>legend(‘off’) >>legend(…,pos) >>help legend % give usage Arrow & special characters, Greek characters Annotation with text() >>text(x,y,‘string1’) Add string at (x,y) >>gtext(‘string’) Add string at mouse click interactively

20 Example - Title, Legend, Label & Text Function >> % Example disp('formatting graph') t=-pi:0.1:pi; plot(t,sin(t),t,cos(t)) title('Function of Sine and Cosine','FontSize',18) xlabel('t=-\pi to \pi','FontSize',16) ylabel('sin(t) & cos(t)','Fontsize',16) legend('Sine','Cosine') text(-1,sin(-1),'sin(t)') text(2,cos(2),'cos(t)')

21 With Symbol & Greek Letters in Text Strings >>% example p.26 t=0:900; plot(t,0.25*exp( *t)) title('A{\ite}^{\alpha{\i tt}}','FontSize',16) ylabel('Amplitude','FontS ize',16) xlabel('Time\mu sec','FontSize',16) text(300,0.25*exp( *300),'\bullet\lef tarrow0.25{\ite}^{ {\itt}}at {\itt}=300','FontSize', 14)

22 Text Properties Search for ‘text properties’ in help can get the table of character sequence for Greek or mathematic symbols TeX compatible  TeX is a cross-platform typesetting freeware Reference card  What fonts are available? >> c=listfonts % return available fonts Try (put abc… on a plot using gtext):- >> gtext('\fontname{roman}\fontsize{20}abc') gtext('\fontname{arial}\fontsize{20}\bfabc\fon tsize{10}\beta\phi')

23 Axis Ticks t=0:100; plot(t,sin(t/100*2*pi)); set(gca,'XTick',0:5:100) grid

24 Axis Tick (cont. example) labels={'0',' ','10',' ','20',' ','30',' ','40',' ','50',' ','60',' ','70',' ','80',' ','90',' ','100'} set(gca,'XTickLabel',labels)

25 Example on Tick & Labels temp=[ ]; days={'sun','mon','tue','wed','thur','fri','sat'}; plot(1:7,temp); axis([ ]) set(gca,'XTickLabel',days); grid title('Temperature','FontSize',16)

26 Bar Chart BAR(Y) uses the default value of X=1:M. For vector inputs, BAR(X,Y) or BAR(Y) draws LENGTH(Y) bars. The colors are set by the colormap. BAR(X,Y,WIDTH) or BAR(Y,WIDTH) specifies the width of the bars. Values of WIDTH > 1, produce overlapped bars. The default value is WIDTH=0.8 BAR(...,'grouped') produces the default vertical grouped bar chart. BAR(...,'stacked') produces a vertical stacked bar chart. BARH Horizontal bar graph BAR3 3-D bar graph BAR3H Horizontal 3-D bar graph

27 Example on Bar Chart Y=round(rand(5,3)*10) subplot 221 bar(Y) title('Group') subplot 222 bar(Y,'stack') title('stack') subplot 223 barh(Y,'stack') title('stack') subplot 224 bar(Y,1.5) title('width=1.5')

28 Example on Bar Chart

29 Example on Bar3 Y=cool(7); subplot(2,2,1) bar3(Y) title('Default') subplot(2,2,2) bar3(Y,'group') title('Group') subplot(2,2,3) bar3(Y,'stack') subplot(2,2,4) bar3h(Y,'stack') % COOL(M) returns an M-by-3 matrix containing a "cool" colormap.

30 Example – bar3h

31 Example on Filled Area Plots % An area plot displays elements in Y as one or more curves and fills the area beneath each curve. sales=[ ]; x=90:94; profits=[ ]; area(x,sales,'FaceColor',[.5.9.6],'EdgeColor','b','LineWidth',2) hold on area(x,profits,'FaceColor',[ ],'EdgeColor','y','LineWidth',2) hold off set(gca,'XTick',[90:94]) text(92,20,'Expenses') text(91,60,'Profits')

32 Example on Area Filled Plot

33 Example on Pie Charts x=[ ]; explode=[ ]; subplot 221 pie(x) % pie chart title('2D-Default') subplot 222 pie(x,explode) % explode pie chart title('2D-explode') subplot 223 pie3(x) % 3D pie chart title('3D-Default') subplot 224 pie3(x,explode) % 3D explode pie chart title('3D-Default')

34 Example on Pie Charts

35 Example on Histograms X=randn(10000,3); subplot(2,1,1) hist(X) title('Histogram showing 10 bins') subplot(2,1,2) hist(X,20) title('Histogram showing 20 bins')

36 Example on Histograms

37 Example on Compass Plot COMPASS(U,V) draws a graph that displays the vectors with components (U,V) as arrows emanating from the origin. x=floor(randn(10,1)*10) y=floor(randn(10,1)*10) compass(x,y)

38 Compass Plot (Cont. example) z=[-0.9+5i,-0.9-5i, i, i, , i, i,-4.3, i, i] compass(z)