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

Similar documents
PROGRAMMING WITH MATLAB WEEK 6

INTRODUCTION TO MATLAB PLOTTING WITH MATLAB

Mechanical Engineering Department Second Year (2015)

Basic Graphs. Dmitry Adamskiy 16 November 2011

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

Computer Programming in MATLAB

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

Additional Plot Types and Plot Formatting

Dr Richard Greenaway

This module aims to introduce Precalculus high school students to the basic capabilities of Matlab by using functions. Matlab will be used in

Graphics and plotting techniques

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

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

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

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

QUICK INTRODUCTION TO MATLAB PART I

MATLAB Introduction to MATLAB Programming

DSP Laboratory (EELE 4110) Lab#1 Introduction to Matlab

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

Getting Started. Chapter 1. How to Get Matlab. 1.1 Before We Begin Matlab to Accompany Lay s Linear Algebra Text

A General Introduction to Matlab

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

TOPIC 6 Computer application for drawing 2D Graph

fplot Syntax Description Examples Plot Symbolic Expression Plot symbolic expression or function fplot(f) fplot(f,[xmin xmax])

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

A Tutorial on Matlab Ch. 3 Programming in Matlab

Chapter 2. MATLAB Fundamentals

Introduction to Matlab to Accompany Linear Algebra. Douglas Hundley Department of Mathematics and Statistics Whitman College

MATLAB Guide to Fibonacci Numbers

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

Fondamenti di Informatica Examples: Plotting 2013/06/13

Lab #1 Revision to MATLAB

Appendix A. Introduction to MATLAB. A.1 What Is MATLAB?

PowerPoints organized by Dr. Michael R. Gustafson II, Duke University

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

PART 1 PROGRAMMING WITH MATHLAB

An Introduction to MATLAB II

Basic Beginners Introduction to plotting in Python

MATLAB Modul 3. Introduction

LESSON: Working with line graphs questions

What is MATLAB? What is MATLAB? Programming Environment MATLAB PROGRAMMING. Stands for MATrix LABoratory. A programming environment

Matlab Tutorial. The value assigned to a variable can be checked by simply typing in the variable name:

Logical operators: R provides an extensive list of logical operators. These include

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

Introduction to. The Help System. Variable and Memory Management. Matrices Generation. Interactive Calculations. Vectors and Matrices

Objectives. 1 Basic Calculations. 2 Matrix Algebra. Physical Sciences 12a Lab 0 Spring 2016

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

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

Objectives. 1 Running, and Interface Layout. 2 Toolboxes, Documentation and Tutorials. 3 Basic Calculations. PS 12a Laboratory 1 Spring 2014

Scientific Computing with MATLAB 2. Graphics for Research & Publication

What is Matlab? A software environment for interactive numerical computations

PERI INSTITUTE OF TECHNOLOGY DEPARTMENT OF ECE TWO DAYS NATIONAL LEVEL WORKSHOP ON COMMUNICATIONS & IMAGE PROCESSING "CIPM 2017" Matlab Fun - 2

Graphics Example a final product:

MATLAB Basics. User-Defined Functions

Computing Fundamentals Plotting

MATH (CRN 13695) Lab 1: Basics for Linear Algebra and Matlab

1 Introduction to Matlab

AMS 27L LAB #2 Winter 2009

Introduction to MATLAB LAB 1

Telemark University College Department of Electrical Engineering, Information Technology and Cybernetics. MathScript

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

Introduction to MATLAB: Graphics

Plotting x-y (2D) and x, y, z (3D) graphs

Plotting - Practice session

Dr. Iyad Jafar. Adapted from the publisher slides

Introduction and MATLAB Basics

MATLAB Modul 2. Introduction to Computational Science: Modeling and Simulation for the Sciences, 2 nd Edition

More on Plots. Dmitry Adamskiy 30 Nov 2011

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

ENGR 1181 Final Exam: Practice Problem Solutions

MATLAB Tutorial III Variables, Files, Advanced Plotting

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

Introduction to Matlab

Lecture 6: Plotting in MATLAB

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

Computational Modelling 102 (Scientific Programming) Tutorials

MATLAB Tutorial EE351M DSP. Created: Thursday Jan 25, 2007 Rayyan Jaber. Modified by: Kitaek Bae. Outline

Introduction to Python and NumPy I

Getting Started with DADiSP

Purpose of the lecture MATLAB MATLAB

Spring 2010 Instructor: Michele Merler.

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

ENGR Fall Exam 1

Prof. Manoochehr Shirzaei. RaTlab.asu.edu

Matlab Handout Nancy Chen Math 19 Fall 2004

Introduc)on to Matlab

CCNY. BME 2200: BME Biostatistics and Research Methods. Lecture 4: Graphing data with MATLAB

EE 350. Continuous-Time Linear Systems. Recitation 1. 1

C =

Introduction to Matlab. WIAA Technical Workshop #2 10/20/2015

Basic plotting commands Types of plots Customizing plots graphically Specifying color Customizing plots programmatically Exporting figures

Simfit. Stack Plot. Rows. Columns. Titles and Legends

LabVIEW MathScript Quick Reference

Working with Charts Stratum.Viewer 6

Introduction to Matlab

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.

Technology Assignment: Scatter Plots

A very brief Matlab introduction

1. Register an account on: using your Oxford address

Markov chain Monte Carlo methods

Transcription:

Plotting Continued: You can change the line style by adding some information in the plot command within single quotation marks. y = x.^2; plot(x,y, '-xr') xlabel('x, meters') ylabel('y, meters squared') - changes the line type to solid x puts x-marks at the data points r changes the line color to red Table 5.2 (page 147) in your book shows you the various line type, point type, and color options. Unfortunately, some of the line types may not be available in Octave. Line Type: Point Type: Color: - solid. point b blue : dotted x x-mark g green -. dash-dot + plus r red -- dashed * star k black 1

Plotting Points (no line): Sometimes you just want to plot data points without a line connecting them. Simply omit the line type in the format string. In m-file: y = x.^2; plot(x,y,'or') % NOTICE: The dashes have been omitted. xlabel('x, meters') ylabel('y, meters squared') 2

Multiple plots on same figure: Often you want to compare data on the same figure. There are a couple ways to do this. (1) Using the hold on command. Every time you call the plot( ) command, a new figure is created. The hold on command will prevent a new figure from overwriting the previous figure. More figures can be layered until the hold off command is issued. In main.m: y = x.^2; z = x.^(3/2) plot(x,y,'-xr') xlabel('x, meters') ylabel('y, meters squared') hold on; plot(x,z); hold off; If I did not include the hold on command, only the blue line would be seen. 3

There is a way to plot multiple sets of data on the same graph without using the hold on/hold off commands. (2A) Put multiple output in a single plot( ) command General form. You can use a single plot( ) command to do the same task. The general form is, plot(x1, y1, 'formatting for plot1', x2, y2, 'formatting for plot2', etc ) Returning to our previous example, In main.m: y = x.^2 z = x.^(3/2) plot(x,y, ':xr', x, z, '-og') xlabel('x') ylabel('y,z') 4

(2B) Put multiple output in a single plot( ) command Using same x values If your x values are the same for multiple sets of data, such as in the example above, you can simplify the plot( ) command by storing all the different output in a single matrix. In main.m: y = x.^2 z = x.^(3/2) OUTPUT = [y ; z]; % The different data must be placed in different rows. plot(x,output) xlabel('x') ylabel('y,z') 5

Legends: When you put multiple sets of data on the same figure, you often want to include a legend. legend('data1 info', 'data2 info', etc ) Example: y = x.^2 z = x.^(3/2) plot(x,y, ':xr', x, z, ':og') xlabel('x') ylabel('y,z') legend('x^{2}', 'x^{1.5}' ) 6

Example: Plot the trajectory of cannon balls shot off a cliff with different v0. The cliff is at (0,100). In m-file: x0 = 0; y0 = 100; g = -9.81; angle = 45; t = (0:1:10); v0 = 50; x1 = x0 + v0x.*t ; y1 = y0 + v0y.*t + 0.5*g*t.^2 ; v0 = 100; x2 = x0 + v0x.*t ; y2 = y0 + v0y.*t + 0.5*g*t.^2 ; v0 = 150; x3 = x0 + v0x.*t ; y3 = y0 + v0y.*t + 0.5*g*t.^2 ; plot(x1,y1,x2,y2,x3,y3) xlabel('x, meters'); ylabel('y, meters'); legend('v0=50', 'v0=100', 'v0=150'); 7

8

Subplots: Another way to present multiple sets of data on the same figure is using subplots. This command allows you to subdivide the graphing window into a grid of M rows and N columns. subplot(m,n,p) The variable p identifies the position where the subplot will be drawn. The value of p is increased in row order. For example, if M and N are both 2, then there will be 4 locations for subplots and then the value of p at each of those locations is, p=1 p=2 p=3 p=4 In m-file: clear;clc; x0 = 0; y0 = 100; g = -9.81; angle = 45; t = (0:1:10); v0 = 50; x1 = x0 + v0x.*t ; y1 = y0 + v0y.*t + 0.5*g*t.^2 ; v0 = 100; x2 = x0 + v0x.*t ; y2 = y0 + v0y.*t + 0.5*g*t.^2 ; v0 = 150; x3 = x0 + v0x.*t ; y3 = y0 + v0y.*t + 0.5*g*t.^2 ; subplot(2,2,1) plot(x1,y1) xlabel('x, meters'); ylabel('y, meters'); title('plot 1'); grid off; 9

subplot(2,2,2) plot(x2,y2) xlabel('x, meters'); ylabel('y, meters'); title('plot 2'); subplot(2,2,3) plot(x2,y2) xlabel('x, meters'); ylabel('y, meters'); title('plot 3'); 10

We could have used a for loop to do the same task: In m-file: x0 = 0; y0 = 100; g = -9.81; angle = 45; t = (0:1:10); v0 = 50; for i=1:3 x = x0 + v0x.*t ; y = y0 + v0y.*t + 0.5*g*t.^2 ; subplot(2,2,i) plot(x,y) xlabel('x, meters'); ylabel('y, meters'); titletxt = ['Plot ', num2str(i)]; title(titletxt); v0 = v0 + 50; end 11