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

Similar documents
Armstrong State University Engineering Studies MATLAB Marina Algorithm Development I Primer

INTRODUCTION TO MATLAB PLOTTING WITH MATLAB

Computing Fundamentals Plotting

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

Plotting - Practice session

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

PROGRAMMING WITH MATLAB WEEK 6

UNIVERSITI TEKNIKAL MALAYSIA MELAKA FAKULTI KEJURUTERAAN ELEKTRONIK DAN KEJURUTERAAN KOMPUTER

Pre-Lab Excel Problem

PC-MATLAB PRIMER. This is intended as a guided tour through PCMATLAB. Type as you go and watch what happens.

INTRODUCTION TO MATLAB, SIMULINK, AND THE COMMUNICATION TOOLBOX

GRAPHICS AND VISUALISATION WITH MATLAB

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

ENED 1090: Engineering Models I Homework Assignment #2 Due: Week of September 16 th at the beginning of your Recitation Section

Dr. Iyad Jafar. Adapted from the publisher slides

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

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

Armstrong State University Engineering Studies MATLAB Marina Switch-Case Statements Primer

A Guide to Using Some Basic MATLAB Functions

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

Additional Plot Types and Plot Formatting

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

Mechanical Engineering Department Second Year (2015)

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

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

ROSE-HULMAN INSTITUTE OF TECHNOLOGY

Armstrong Atlantic State University Engineering Studies MATLAB Marina Sorting Primer

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

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

ECE 202 LAB 3 ADVANCED MATLAB

Technology Assignment: Scatter Plots

Graphics Example a final product:

Basic Graphs. Dmitry Adamskiy 16 November 2011

TABLE OF CONTENTS INTRODUCTION... 2 OPENING SCREEN BEGIN ANALYSIS... 4 Start a New File or Open a Previously Saved File... 4

Dr Richard Greenaway

Armstrong State University Engineering Studies MATLAB Marina 2D Arrays and Matrices Primer

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

Introduction to the MATLAB SIMULINK Program

Plotting using Matlab. Vytautas Astromskas

Physics 251 Laboratory Introduction to Spreadsheets

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

STIPlotDigitizer. User s Manual

TOPIC 6 Computer application for drawing 2D Graph

What is Matlab? A software environment for interactive numerical computations

Introduction to MATLAB

FF505/FY505 Computational Science. MATLAB Graphics. Marco Chiarandini

PART 1 PROGRAMMING WITH MATHLAB

CSE 123. Plots in MATLAB

Spreadsheet View and Basic Statistics Concepts

ENGR Fall Exam 1

You can change the line style by adding some information in the plot command within single quotation marks.

QUICK INTRODUCTION TO MATLAB PART I

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

3D Surface Plots with Groups

Introduction to MATLAB: Graphics

BioFuel Graphing instructions using Microsoft Excel 2003 (Microsoft Excel 2007 instructions start on page mei-7)

MATLAB BASICS. < Any system: Enter quit at Matlab prompt < PC/Windows: Close command window < To interrupt execution: Enter Ctrl-c.

Introduction to MatLab. Introduction to MatLab K. Craig 1

Points Lines Connected points X-Y Scatter. X-Y Matrix Star Plot Histogram Box Plot. Bar Group Bar Stacked H-Bar Grouped H-Bar Stacked

Designed by Jason Wagner, Course Web Programmer, Office of e-learning NOTE ABOUT CELL REFERENCES IN THIS DOCUMENT... 1

MATLAB Fundamentals. Berlin Chen Department of Computer Science & Information Engineering National Taiwan Normal University

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

Nuts & Bolts guide to MATLAB

Matlab Introduction. Scalar Variables and Arithmetic Operators

Getting Started with DADiSP

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

Chapter 2 Surfer Tutorial

UNIVERSITI TEKNIKAL MALAYSIA MELAKA FAKULTI KEJURUTERAAN ELEKTRONIK DAN KEJURUTERAAN KOMPUTER

Prof. Manoochehr Shirzaei. RaTlab.asu.edu

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

Chapter 4: Programming with MATLAB

Lecturer: Keyvan Dehmamy

Part #6. A0B17MTB Matlab. Miloslav Čapek Filip Kozák, Viktor Adler, Pavel Valtr

COMPUTER TECHNOLOGY SPREADSHEETS BASIC TERMINOLOGY. A workbook is the file Excel creates to store your data.

Graphics and plotting techniques

MICROSOFT EXCEL Working with Charts

HOUR 12. Adding a Chart

Creating a Basic Chart in Excel 2007

Technical Documentation Version 7.3 Output

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

MATLAB Tutorial. Digital Signal Processing. Course Details. Topics. MATLAB Environment. Introduction. Digital Signal Processing (DSP)

Introduction to MATLAB

ME 105 Homework 4 A Movie Stunt Simulation with Graphical User Interface

SciGraphica. Tutorial Manual - Tutorials 1and 2 Version 0.8.0

Creates a 1 X 1 matrix (scalar) with a value of 1 in the column 1, row 1 position and prints the matrix aaa in the command window.

Lecture 6: Plotting in MATLAB

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

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

Microsoft Excel Chapter 3. Working with Large Worksheets, Charting, and What-If Analysis

Microsoft Excel Chapter 3. What-If Analysis, Charting, and Working with Large Worksheets

252 APPENDIX D EXPERIMENT 1 Introduction to Computer Tools and Uncertainties

KaleidaGraph. Version 4.1

PASS Sample Size Software

Computer Programming in MATLAB

Purpose of the lecture MATLAB MATLAB

Introduction to Matlab

Getting Started with MATLAB

MATLAB Guide to Fibonacci Numbers

Introduction to graphics

Excel R Tips. is used for multiplication. + is used for addition. is used for subtraction. / is used for division

Transcription:

Armstrong Atlantic State University Engineering Studies MATLAB Marina D Plotting Primer Prerequisites The D Plotting Primer assumes knowledge of the MATLAB IDE, MATLAB help, arithmetic operations, built in functions, scripts, variables, arrays, logic expressions, conditional structures, iteration, functions, debugging, characters and strings, cell arrays, structures, and file input and output. Material on these topics is covered in the MATLAB Marina Introduction to MATLAB module, MATLAB Marina Variables module, MATLAB Marina Arrays module, MATLAB Marina Logic Expressions module, MATLAB Marina Conditional Structures module, MATLAB Marina Iteration module, MATLAB Marina Functions module, MATLAB Marina debugging module, MATLAB Marina Character and Strings module, MATLAB Marina Cell Arrays module, MATLAB Marina Structures module, and MATLAB Marina File Input and Output module. Learning Objectives. Be able to generate and appropriately annotate D plots using MATLAB. Terms figure window, D plot, parametric plot MATLAB Functions, Keywords, and Operators figure, plot, subplot, xlabel, ylabel, title, legend, gtext, grid, axis, clf, close Figure Windows MATLAB plots are displayed in figure windows (figure containers). The MATLAB function figure creates a new figure window which can be referenced by its figure number and figure(number) creates a figure with the specified figure number or makes the specified figure the current active figure. The MATLAB function clf clears the current figure window and clf(number) clears the specified figure window. The MATLAB function close closes the current figure window, close(number) closes the specified figure window, and close all closes all open figure windows. Two Dimensional Plotting (D Plotting) Two-dimensional plots can be done using the MATLAB plot function. The statement plot(x,y) creates a two-dimensional plot using the vector x as the x-axis values and the vector y as the y-axis values. The vectors x and y must be the same length. If plot is called with a single argument, plot(y), then the values of y are plotted versus their vector index. Multiple plots can be placed on the same axes, plot(t,x,t,x) plots t vs. x and t vs. x on the same axes. The scale of each axis and the axes ticks are added automatically by MATLAB. Plots

are placed in the active figure window. If there is not an active figure window, the plot command will create and open a figure window (starting with figure ). The MATLAB program of Figure a generates the plot of Figure b, f ( t) e t = for t seconds. Plots can be titled and labeled using the title, xlabel, ylabel, and text functions. The title function places a text string centered on the top of the figure. The xlabel and ylabel functions place labels on the x and y axis respectively. The text function allows one to place a text string anywhere in the figure and the gtext function allows one to place a text string using the mouse curser. MATLAB also has functions: grid to place a grid on the plot, axis to specify the x and y axis limits, and legend to create a legend. % Plot of -exp(-t), t = to sec t = ( :. : ); f = - exp(-t); figure() plot(t, f) xlabel('t (sec)'); ylabel('f(t) = - exp(-t)'); grid Figure a, MATLAB Program for D Plot.7..5 f(t) = - exp(-t)..3.....3..5..7.8.9 t (sec) Figure b, -D Plot The figure properties can also be modified through the figure Insert and Edit menus. The insert menu has selections corresponding to the MATLAB figure functions as well as options to label the figure with shapes, lines and arrows. The edit menu allows axis ranges, labels, titles to be set through the Axes properties selection. Figures can be copied and pasted in Microsoft Word documents via the Copy Figure selection.

Figure a, Figure Insert Menu Figure b, Figure Edit Menu The MATLAB program of Figure generates the plots if Figures 3a - 3c. Figure 3a shows the plot of s x versus s y generated using the MATLAB plot function. The line width was specified to be (twice as thick as the default). The plot of Figure 3a is a D parametric plot. The x and y axis variables are functions of a separate independent variable t. x projectile motion of an artillery shell height in ft.8....8... 3 distance in ft 5 7 8 x Figure 3a, Plot of Projectile Motion Figure 3b shows multiple plots on the same axes, notice that MATLAB automatically chooses a new color for each new plot on the same axes (blue for first, green for second). The grid on 3

statement gives the background grid. The grid off statement will turn off the background grid. 8 x horizontal and vertical postition vs. time 7 position in ft 5 3 3 5 7 time in sec Figure 3b, Plot of Projectile Motion, Two Plots on Same Axes position in ft 8 x position and velocity vs. time sx sy 3 5 7 time in seconds velocity in ft/s - vx vy - 3 5 7 time in seconds Figure 3c, Plot of Projectile Motion, Multiple Axes Figure 3c shows two plots on separate axes in the same figure window. Multiple axes in a figure can be created using the subplot function; subplot(m,n,p) breaks the figure window up into a m by n grid and specifies the pth axes for the plot. The axes are numbered from left to right along each row starting with the top row, then the second row, etc. For example, subplot(3,,) creates a 3 row by column grid and specifies that the current plot should

be placed in the first row, subplot(3,,) would specify the second row, and subplot(3,,3) would specify the third row. The legend is created with the MATLAB legend function. The MATLAB ginput function allows one to get points from the current axes. The curser is positioned via the mouse and points are returned when the mouse button or any key on the keyboard is hit (except return). For example, [x,y] = ginput() gets two points from the current axes and returns two vectors containing the x and y coordinates of the points. The statement [x,y] = ginput gets an unlimited number of points until the return key is pressed. % D projectile motion sx =.; sy =.; v = 55.; % muzzle velocity in ft/s gx =.; gy = -3.8; % gravity in ft/s^ % get the muzzle angle from the user and convert to radians angle = input('input the muzzle angle in degrees: '); theta = angle*pi/8; % barrel angle in radians % calculate the x and y components of muzzle velocity vx = v*cos(theta); vy = v*sin(theta); % calculate the range for the shell and time to max range range = -v^*sin(*theta)/gy; tmax = range/vx; t = [:.:tmax]; % calculate the position and velocity of the shell vx = vx + gx*t; vy = vy + gy*t; sx = sx + vx*t +.5*gx*t.*t; sy = sy + vy*t +.5*gy*t.*t; % plot the projectile motion with a line width of figure() plot(sx,sy,'linewidth',); xlabel('distance in ft'); ylabel('height in ft'); title('projectile motion of an artillery shell'); Figure (First Part), MATLAB Program for Plots in Figures 3a 3c 5

% multiple plots on same graph figure(3) plot(t,sx,t,sy); title('horizontal and vertical postition vs. time'); xlabel('time in sec'); ylabel('position in ft'); grid on; % multiple plots in same figure window (different graphs) figure() subplot(,,),plot(t,sx,'-',t,sy,':'); subplot(,,),xlabel('time in seconds'); subplot(,,),ylabel('position in ft'); subplot(,,),grid on; subplot(,,),plot(t,vx,'-',t,vy,':'); subplot(,,),xlabel('time in seconds'); subplot(,,),ylabel('velocity in ft/s'); subplot(,,),grid on; subplot(,,),title('position and velocity vs. time'); subplot(,,),legend('sx','sy'); subplot(,,),legend('vx','vy'); Figure (Second Part), MATLAB Program for Plots in Figures 3a 3c Other Useful Plotting Functions Other MATLAB D plotting functions are stem, semilogx, semilogy, loglog, bar, hist, pie, and polar. Other functions that are useful with plots are hold and view. See MATLAB s help for more info on the different plot types. MATLAB allows one to specify the point style, line color, and line style of plots via an optional control string argument of the plot function. The script of Figure 5a generates the plot of Figure 5b. In this case only the data points are plotted with point style of + and point color black. There are no lines joining the data points (no interpolation between points). See MATLAB's help on the different point and line styles of the plot function. % Plot of Sampled Data xn = [., -.,.,.7, -.8,.8,.3,., 3.3, -.5,.5, -.3,.]; figure() plot(xn,'k+') xlabel('sample'); ylabel('x[n]'); Figure 5a, Program for Figure 5b

7 5 3 x[n] - - -3 8 sample Figure 5b, Plot of Sampled Data, No lines Other Useful Annotation Operations The Figure window toolbar provides many other options for viewing annotating plots. The Figure Insert menu has options for inserting lines, arrows, and textboxes along with axis labels, titles, legends, and shapes. The Figure window toolbar has icons for zooming, panning, rotating, and various annotation operations. Selecting the toolbar magnifying glass icon with + or inside allows one to zoom in or out on a region of a plot. Selecting the toolbar hand icon allows one to pan to the left/right and up/down of a plot. The toolbar also has an insert legend icon which allows one to insert a legend and a data curser icon which allows one to annotate the plot with the values at the location of the data curser. Keep in mind that any annotation done via the toolbar or menus is for the current Figure window and would need to be redone whenever the plot was generated. Last modified Monday, September 3, 3 This work by Thomas Murphy is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3. Unported License. 7