Matlab Training Sessions 6,7: Plotting. Course Outline Weeks: 1.Introduction to Matlab and its Interface (Jan 13 2009) 2.Fundamentals (Operators) 3.Fundamentals.

Slides:



Advertisements
Similar presentations
Lab # 03- SS Basic Graphic Commands. Lab Objectives: To understand M-files principle. To plot multiple plots on a single graph. To use different parameters.
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
Lecture (4) Plotting & Programming (1) Eng. Osama Talaat 1.
2D Plots 1 ENGR 1181 MATLAB 12.
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.
1. Overview 2. plot in 2D 3. Plot in 3D 4. Other possible charts 5. Engineers: label your plots! 6. Plots & Polynomial Plotting 11.
Digital Image Processing Lecture11: Histogram Processing.
MA/CS375 Fall MA/CS 375 Fall 2002 Lecture 4.
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:
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 332:202 Discrete Mathematics Spring 2007.
Floyd, Digital Fundamentals, 10 th ed EET 2259 Unit 11 Charts and Graphs  Read Bishop, Chapter 7.  Lab #11 and Homework #11 due next week.
Introduction to Excel 2007 Part 3: Bar Graphs and Histograms Psych 209.
An introduction to Plotting in MATLAB Rikard Johansson Department of Biomedical Engineering (IMT) Linköping University
Instructor: Professor Cora Martinez, PhD Department of Civil and Environmental Engineering Florida International University.
EPSII 59:006 Spring Outline Managing Your Session File Usage  Saving Workspace  Loading Data Files  Creating M-files More on Matrices Review.
 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.
STATISTICAL GRAPHS.
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.
„  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.
COMP 116: Introduction to Scientific Programming Lecture 5: Plotting, Scripts and publishing.
Name : Tatiana “Tania” Harrison Office : 216 Phone number: CWU page: Syllabus Name :
MAE 1202: AEROSPACE PRACTICUM An Introduction to MATLAB: Part 2 Mechanical and Aerospace Engineering Department Florida Institute of Technology Developed.
Getting Started with TI-Interactive. TI-Interactive TI-Interactive can be used to create a variety of graphs. Scatter Plots, Line Plots, Histograms, Modified.
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.
Barbara/Pratik/Yu. Outline Matlab desktop M-files Variables Arrays Plots.
ENG 1181 College of Engineering Engineering Education Innovation Center MATLAB – 2D Plots 1 Go to the class drive: ---> MatLab - Graphing ---> Seed Files.
Introduction to MATLAB Session 5 Simopekka Vänskä, THL 2010.
Histograms Lecture 14 Sec Tue, Sep 26, 2006.
Matlab Screen  Command Window  type commands  Current Directory  View folders and m-files  Workspace  View program variables  Double click on a.
UW CSE 190p Section 7/26, Summer 2012 Dun-Yu Hsiao.
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.
© 2011 Delmar, Cengage Learning Chapter 4 Working with Frames.
Histograms Lecture 14 Sec Fri, Feb 8, 2008.
ELG 3120 Lab 2 TAs Wei Zhang Ozgur Ekici (Section A) (Section B)
1 Lecture 5 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.
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.
NET 222: COMMUNICATIONS AND NETWORKS FUNDAMENTALS ( NET 222: COMMUNICATIONS AND NETWORKS FUNDAMENTALS (PRACTICAL PART) Lab 2 : potting to Matlab Networks.
CS100A, Fall 1998, Lecture 191 CS100A, Fall 1998 Lecture 19, Thursday Nov 05 Matlab Concepts: Matlab arrays Matlab subscripting Matlab plotting.
CS100A, Fall 1998, Lecture 201 CS100A, Fall 1998 Lecture 20, Tuesday Nov 10 More Matlab Concepts: plotting (cont.) 2-D arrays Control structures: while,
EEE 242 Computer Tools for Electrical Engineering
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.
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.
Matlab Training Session 4: Control, Flow and Functions
3D-Graphs A 3D surface is defined as: z = f(x, y)
Lecture 25.
Lecture 25: Exploring data
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 How to use (using M-files)
Introduction to MATLAB Plotting LAB 3
Plotting Signals in MATLAB
Matlab Training Session 2: Matrix Operations and Relational Operators
Introduction to Matlab
Presentation transcript:

Matlab Training Sessions 6,7: Plotting

Course Outline Weeks: 1.Introduction to Matlab and its Interface (Jan ) 2.Fundamentals (Operators) 3.Fundamentals (Flow) 4.Importing Data 5.Functions and M-Files 6.Plotting (2D and 3D) 7.Statistical Tools in Matlab 8.Analysis and Data Structures Course Website:

Week 5 Lecture Outline Plotting Data A.Basics B.Generating data C.2D Plots (Line, Scatter, Bar) D. Plot Features

Basics Matlab has a powerful plotting engine that can generate a wide variety of plots.

Generating Data Matlab does not understand functions, it can only use arrays of numbers. –a=t 2 –b=sin(2*pi*t) –c=e -10*t note: matlab command is exp() –d=cos(4*pi*t) –e=2t 3 -4t 2 +t Generate it numerically over specific range Try and generate a-e over the interval 0:0.01:2 t=0:0.01:10; %make x vector y=t.^2; %now we have the appropriate y % but only over the specified range

Line/Scatter Simplest plot function is plot() Try typing plot(y) –Matlab automatically generates a figure and draws the data and connects its lines –Looks right, but the x axis units are incorrect Type plot(x,y), will look identical but have correct x-axis units Plot(x1,y1,s1,x2,y2,s2, …) many plots in one command Plot(x) where x is a matrix, will result in plotting each column as a separate trace

Line/Scatter Plot a and then plot b –What do you see? –Only b Matlab will replace the current plot with any new one unless you specifically tell it not to To have both plots on one figure use the hold on command To make multiple plots use the figure command plot(t,a) plot(t,b) % Put a and b on one plot plot(t,a); hold on; plot(t,b); % Make two plots plot(t,a); figure; plot(t,b);

Hold On / Hold Off Hold on command only needs to be issued once per figure, thus calling hold on will result in all subsequent plot commands going to one figure unless a new figure command is issued or hold off is used. plot(a); Hold on; plot(b); plot(c); Hold off; Figure; plot(d); plot(a); Hold on; plot(b); plot(c); Hold off; plot(d); plot(a); Hold on; plot(b); plot(c); Figure; plot(d);

Linespec Currently, all the plots were done in the Matlab default color … blue This and many other features can be changed by selecting a different option within the plot command % red line Plot(t,a,’r’); Hold on; % black line Plot(t,b,’k’); % green dots Plot(t,c,’g.’); % cyan x’s Plot(t,d,’cx’) % dashed magenta % line with o’s Plot(t,e,’--om’)

Linespec Now we have added color, line style and markers to the data We can also modify line width, marker edge and fill color and marker size % dashed magenta % line with o’s, … Plot(t,e,’--om’, ‘LineWidth’,3,'MarkerEdgeColor',‘k‘, 'MarkerFaceColor',‘y‘, MarkerSize,9)

Labels, Title and Legend To add labels to the x and y axes, we can use the xlabel and ylabel commands To add a title, use the title command To add a legend, use the legend command plot(t,a,t,b,’r’,t,c,’--om’); %generate all plots in one shot title(‘Random Plots’) xlabel(‘time(ms)’); ylabel(‘f(t)’) legend(‘Function 1’,’Function 2’,’Function 3’);

Quick Assignment 1 Plot a as a thick black line Plot b as a series of red circles. Label each axis, add a title and a legend

Quick Assignment 1 figure plot(t,a,'k','LineWidth',3); hold on; plot(t,b,'ro') xlabel('Time (ms)'); ylabel('f(t)'); legend('t^2','sin(2*pi*t)'); title('Mini Assignment #1')

Axis commands We can alter the displayed range and other parameters of the plot by using the axis command –Axis([xmin xmax ymin ymax]) –Axis equal; –Axis square; Figure; Plot(t,a,’r’); Axis([ ]);

Error Bars In addition to markers, matlab can generate error bars for each datapoint using the errorbar command –errorbar(x,y,e) or errorbar(x,y,ll,lu); –Will generate line plus error bars at y+/-e or (y-ll,y+lu) t2 = 0:1:10; f = t2+(rand(1,length(t2))-0.5); err1 = 0.1*f; err2_l = 0.1*f; err2_u = 0.25*f; errorbar(t2,f,err1); figure; errorbar(t2,f,err2_l, err2_u);

Subplots So far we have only been generating individual plots Matlab can also generate a matrix of plots using the subplot command figure; subplot(2,2,1) plot(t,a); subplot(2,2,2) plot(t,b); subplot(2,2,3) plot(t,c); subplot(2,2,4) plot(t,d);

Quick Assignment 2 Generate a 3x1 array of figures, each with a title Axis range of plots 1 and 2 should be 0 to 1 on x and y Plot 1 should include function a and b (color code) Plot 2 should include c and d (color code) Plot 3 should include f with error bars of your liking

Quick Assignment 2 figure subplot(3,1,1) plot(t,a,t,b,'r'); axis([ ]); title('Functions a and b') subplot(3,1,2) plot(t,c,t,d,'m'); axis([ ]); title('Functions c and d') subplot(3,1,3) errorbar(t2,f,err1); title('function f with errorbars')

Bar Graphs So far we have focused on line/scatter plots, the other most common plot type is a bar graph Matlab bar(x,y,width) command will generate a bar graph that is related to the underlying functions where the width of each bar is specified by width (default = 1); Can be used with subplot and all the other features we have discussed so far t3 = 0:1:25; f = sqrt(t3); bar(t3,f);

Histograms Matlab hist(y,m) command will generate a frequency histogram of vector y distributed among m bins Also can use hist(y,x) where x is a vector defining the bin centers –Note you can use histc function if you want to define bin edges instead Can be used with subplot and all the other features we have discussed so far hist(b,10); Figure; Hist(b,[ ]);

Quick Assignment 3 Generate the following data set –It results in multiple noisy repeats of some trial Create mean_x to be the mean of all the trials at each point of x Create std_x to be the standard deviation of all trials at each point of x Add labels and titles t = 0:0.1:1 for(i=1:25) x(i,:) = exp(-10.*t) + 0.5*(rand(1,length(t))-0.5); end

Quick Assignment 3 Make a plot that is to include 2 subplots Plot #1: –Plot each individual trial (25 lines) in thin dotted black lines, tip: remember about how matlab interprets matricies for the plot command. –Plot the mean of the trials with a thick, red, dashed line and error lines surrounding each datapoint that correspond to the standard deviation of each of the points Plot #2: –A histogram that expresses the distribution of the signal at the end of each trial (last sample)

Quick Assignment 3 t = 0:0.1:1 for(i=1:25) x(i,:) = exp(-10.*t) + 0.5*(rand(1,length(t))-0.5); end mean_x = mean(x); std_x = std(x); figure subplot(2,1,1) plot(t,x,'k'); hold on; errorbar(t,mean_x,std_x,'--r','LineWidth', 3); title('Repeats of a Given Task') xlabel('Repeat'); ylabel('Error Rate'); subplot(2,1,2) hist(x(:,11),10) title('Distribution of Endpoint Position'); xlabel('Deviation (mm)') ylabel('Occurances')

Quick Assignment 3

Recap Learned about basic 2D plot functions –plot,bar,hist Dealing with multiple plots and graphs –Hold, figure, subplot Discussed adding features to graphs –Xlabel,title,legend,…

3D Plots Matlab provides a wide range of 3D plot options, we will talk about 3 different plot types. –Mesh, Surf, Contour

Dataset Try [x,y,z] = peaks(25) –Does this work? If not, lets create an arbitrary dataset –x=-10:10; y = -10:10; z=x.^2’*y.^2;

Mesh Connects a series of discrete data points with a mesh –mesh(x,y,z) where X(i) and Y(j) are the intersections of the mesh and Z(i,j) is the height at that intersection –mesh(Z) assumes X and Y are simple 1..N and 1..M

Surf Very similar to mesh, with filled grid

Contour Projection of equal heights of 3D plot onto a 2D plane Use like surf or mesh – contour(x,y,z)

Meshc,surfc Combination surface/mesh and contour plot Use like surf or mesh – meshc(x,y,z)

Plot3 Plots lines and points in space, just like plot but now for an (x,y,z) triple Plot3(x,y,z), each a vector of equal length Use all the same specfiers to generate colors, line-types, etc.

Plot commands Note that almost all 2D plotting commands such as xlabel, ylabel, title will still work in 3D plots 3D plots can be added as subplots just like any other plot type Some other special features and functions exist…

View Changes the view of the current 3D plot –view(az,el) –Az = azimuth (rotation around z-axis) –El = Elevation (rotation around xy-plane) Useful rotations (0,0),(90,0)

Colorbar For the 3D plots, it is useful to add a colorbar to the figure to indicate height. Colorbar(‘vert’) adds a vertical colorbar Colorbar(‘horiz) adds a horizontal colorbar

caxis Allows you to set the range of colors in the plot. Caxis([min max]) will choose the range of colors from the current color map to assign to the plot. Values outside this range will use the min/max available

Colormap Plenty of other controls to personalize the plot –colormap colormap_name sets to new map –Colormap (sets the types of colors that appear in 3D plot). These can be custom of one of several premade –bone Hsv, jet, autumn, vga, summer, … –See help graph3D for more –Use colormapeditor function for graphical selection of color map

Colormap

Next Week Basic Stats / Basic Matlab wrap up

Getting Help Help and Documentation Digital 1.Accessible Help from the Matlab Start Menu 2.Updated online help from the Matlab Mathworks website: 3.Matlab command prompt function lookup 4.Built in Demo’s 5.Websites Hard Copy 3.Books, Guides, Reference The Student Edition of Matlab pub. Mathworks Inc.