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

Similar documents
Mechanical Engineering Department Second Year (2015)

Basic Graphs. Dmitry Adamskiy 16 November 2011

PROGRAMMING WITH MATLAB WEEK 6

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

INTRODUCTION TO MATLAB PLOTTING WITH MATLAB

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

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

! The MATLAB language

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

Matlab Lecture 1 - Introduction to MATLAB. Five Parts of Matlab. Entering Matrices (2) - Method 1:Direct entry. Entering Matrices (1) - Magic Square

Lab #1 Revision to MATLAB

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

Prof. Manoochehr Shirzaei. RaTlab.asu.edu

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

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

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

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

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

Introduction to MATLAB: Graphics

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

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

Introduction to Matlab

UNIVERSITI TEKNIKAL MALAYSIA MELAKA FAKULTI KEJURUTERAAN ELEKTRONIK DAN KEJURUTERAAN KOMPUTER

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

Introduction to MATLAB

Additional Plot Types and Plot Formatting

MATH 2221A Mathematics Laboratory II

Lab of COMP 406 Introduction of Matlab (II) Graphics and Visualization

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

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

PART 1 PROGRAMMING WITH MATHLAB

What is Matlab? A software environment for interactive numerical computations

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

FF505/FY505 Computational Science. MATLAB Graphics. Marco Chiarandini

Computing Fundamentals Plotting

Introduction to MATLAB

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

Dr. Iyad Jafar. Adapted from the publisher slides

Introduc)on to Matlab

MATLAB Introduction to MATLAB Programming

Graphics Example a final product:

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

CSE 123. Plots in MATLAB

Computer Programming in MATLAB

Plotting - Practice session

MATLAB Tutorial. 1. The MATLAB Windows. 2. The Command Windows. 3. Simple scalar or number operations

Graphics and plotting techniques

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

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

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

MATLAB Guide to Fibonacci Numbers

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

MATLAB PROGRAMMING LECTURES. By Sarah Hussein

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

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

MATLAB Laboratory 09/23/10 Lecture. Chapters 5 and 9: Plotting

Matlab Tutorial and Exercises for COMP61021

PyPlot. The plotting library must be imported, and we will assume in these examples an import statement similar to those for numpy and math as

Matlab Tutorial for COMP24111 (includes exercise 1)

NatSciLab - Numerical Software Introduction to MATLAB

Chapter 3: Introduction to MATLAB Programming (4 th ed.)

Introduction to MATLAB

Dr Richard Greenaway

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

1. Register an account on: using your Oxford address

Introduction to Matlab

GRAPHICS AND VISUALISATION WITH MATLAB

1 Introduction to Matlab

Introduction to MATLAB

Chapter 2. MATLAB Fundamentals

Programming 1. Script files. help cd Example:

An Introduction to MATLAB II

Purpose of the lecture MATLAB MATLAB

PyPlot. The plotting library must be imported, and we will assume in these examples an import statement similar to those for numpy and math as

A very brief Matlab introduction

Finding, Starting and Using Matlab

Introduction to Matlab

ECE 201 Matlab Lesson #2 Basic Arithmetic and Plotting. Element-by-Element Arithmetic for Vectors and Matrices

Stokes Modelling Workshop

Math 375 Natalia Vladimirova (many ideas, examples, and excersises are borrowed from Profs. Monika Nitsche, Richard Allen, and Stephen Lau)

DataPlotClasses for REALBasic

Math 7 Elementary Linear Algebra PLOTS and ROTATIONS

Introduction to graphics

MATLAB. The Language of Technical Computing. Getting Started with MATLAB Version 5. Computation. Visualization. Programming

Introduction to MATLAB Programming. Chapter 3. Linguaggio Programmazione Matlab-Simulink (2017/2018)

MATLAB Functions and Graphics

Chapter 2 (Part 2) MATLAB Basics. dr.dcd.h CS 101 /SJC 5th Edition 1

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

Introduction to MATLAB

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

Lecture 6: Plotting in MATLAB

Computational Photonics, Seminar 01 on Introduction into MATLAB, Page 1

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

DATA PLOTTING WITH MATLAB

A General Introduction to Matlab

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

More on Plots. Dmitry Adamskiy 30 Nov 2011

Lab 5: Matlab Tutorial Due Sunday, May 8 at midnight

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

QUICK INTRODUCTION TO MATLAB PART I

Transcription:

What is the answer? >> Logical Subscripting: This kind of subscripting can be done in one step by specifying the logical operation as the subscripting expression. The finite(x)is true for all finite numerical values and false for NaN and Inf A = magic(4) The find Function: The find function determines the indices of array elements that meet a given logical condition. In its simplest form, find returns a column vector of indices. 12

Controlling Command Window Input and Output This section describes how to: Control the appearance of the output values Edit the command line Suppress output from MATLAB commands Enter long commands at the command line The format Command: The format command controls the numeric format of the values displayed by MATLAB. The command affects only how numbers are displayed, not how MATLAB computes or saves them. format short 1.3333 0.0000 format short e 1.3333e+000 1.2345e-006 format short g 1.3333 1.2345e-006 format long 1.33333333333333 0.00000123450000 format long e 1.333333333333333e+000 1.234500000000000e-006 format long g 1.33333333333333 1.2345e-006 format bank 1.33 0.00 format rat 4/3 1/810045 format hex 3ff5555555555555 3eb4b6231abfd271 Command Line Editing: Suppressing Output: if you end the line with a semicolon, MATLAB performs the computation but does not display any output. A = magic (100); Entering Long Command Lines: If a statement does not fit on one line, use three periods,..., followed by Return or Enter to indicate that the statement continues on the next line. For example: 13

Graphics Basic Plotting Creating a Plot: The plot function has different forms. If y is a vector, plot(y) produces a piecewise linear graph of the elements of y versus the index of the elements of y. If you specify two vectors as arguments, plot (x,y) produces a graph of y versus x. After plot, label the axes and add a title. The characters \pi create the symbol π. x = 0:pi/100:2*pi; y = sin(x); plot (x,y) xlabel ('x = 0:2\pi') ylabel ('Sine of x') title('plot of the SineFunction','FontSize',12) Multiple Data Sets in One Graph: Multiple x-y pair arguments create multiple graphs with a single call to plot. y2 = sin(x-.25); y3 = sin(x-.5); plot (x,y,x,y2,x,y3) legend ('sin(x)','sin(x-.25)','sin(x-.5)') Specifying Line Styles and Colors: It is possible to specify color, line styles, and markers (such as plus signs or circles) when you plot your data using the plot command: plot(x,y,'color_style_marker') color_style_marker is a string containing from one to four characters (enclosed in single quotation marks) constructed from a color, a line style, and a marker type: Color strings are 'c', 'm', 'y', 'r', 'g', 'b', 'w', and 'k'. These correspond to cyan, magenta, yellow, red, green, blue, white, and black. Linestyle strings are '-' for solid, '--' for dashed, ':' for dotted, '-.' For dash-dot, and 'none' for no line. The marker types are '+', 'o', '*', and 'x' and the filled marker types 's' for square, 'd' for diamond, '^' for up triangle, 'v' for down triangle, '>' for right triangle, '<' for left triangle, 'p' for pentagram, 'h' for hexagram, and none for no marker. x1 = 0:pi/100:2*pi; x2 = 0:pi/10:2*pi; plot(x1,sin(x1),'r:',x2,sin(x2),'r+')? 14

Adding Plots to an Existing Graph: The hold command enables you to add plots to an existing graph. When you type: hold on. MATLAB adds the new data to the current graph, rescaling the axes if necessary. Figure Windows: Graphing functions automatically open a new figure window if there are no figure windows already on the screen. If a figure window exists, MATLAB uses that window for graphics output.to make an existing figure window the current figure: figure (n) where n is the number in the figure title bar. To open a new figure window and make it the current figure, type: figure Multiple Plots in One Figure: The subplot command enables you to display multiple plots in the same window or print them on the same piece of paper. subplot (m,n,p); partitions the figure window into an m-by-n matrix of small subplots and selects the pth subplot for the current plot. t = 0:pi/10:2*pi; [X,Y,Z] = cylinder (4*cos(t)); subplot (2,2,1); mesh(x) subplot (2,2,2); mesh(y) subplot (2,2,3); mesh(z) subplot (2,2,4); mesh(x,y,z) Axis Labels and Titles: The xlabel, ylabel, and zlabel commands add x-, y-, and z-axis labels. t = -pi:pi/100:pi; y = sin(t); plot (t,y); axis ([-pi pi -1 1]) xlabel ('-\pi \leq {\itt} \leq \pi'); ylabel ('sin(t)') title ('Graph of the sine function') text (1,-1/3,'{\itNote the odd symmetry.}') Controlling the Axes Setting Axis Limits Setting Axis Aspect Ratio axis ([xmin xmax ymin ymax] axis ([xmin xmax ymin ymax zmin zmax]) axis auto axis square axis equal axis auto normal re-enable MATLAB s automatic limit selection Makes the x-axes and y-axes the same length. Makes the individual tick mark increments on the x- and y-axes the same length Returns the axis scaling to its default Setting Axis Visibility axis on or axis off Make the axis visible or invisible Setting Grid Lines grid on or grid off Grid lines on and off. 15

Saving a Figure: Select Save from the File menu, select Export from the File menu or use the saveas command. Mesh and Surface Plots MATLAB defines a surface by the z-coordinates of points above a grid in the x-y plane, using straight lines to connect adjacent points. The mesh and surf plotting functions display surfaces in three dimensions. mesh produces wireframe surfaces that color only the lines connecting the defining points. surf displays both the connecting lines and the faces of the surface in color. Visualizing Functions of Two Variables: To display a function of two variables, z = f (x,y): Generate X and Y matrices consisting of repeated rows and columns, respectively, over the domain of the function. Use X and Y to evaluate and graph the function. The meshgrid function transforms the domain specified by a single vector or two vectors x and y into matrices X and Y for use in evaluating functions of two variables. The rows of X are copies of the vector x and the columns of Y are copies of the vector y. This example evaluates and graphs the two-dimensional sinc function, sin(r)/r, between the x and y directions. R is the distance from origin, which is at the center of the matrix. Adding eps (a MATLAB command that returns the smallest floating-point number on your system) avoids the indeterminate 0/0 at the origin. [X,Y] = meshgrid(-8:.5:8); R = sqrt (X.^2 + Y.^2) + eps; Z = sin(r)./r; Mesh (X,Y,Z, 'EdgeColor','black') Colored Surface Plots: A surface plot is similar to a mesh plot except the rectangular faces of the surface are colored. The color of the faces is determined by the values of Z and the colormap (a colormap is an ordered list of colors). surf (X,Y,Z) colormap hsv colorbar? Surface Plots with Lighting: Lighting is the technique of illuminating an object with a directional light source. After adding the light and setting the lighting method to phong, use the view command to change the view point so you are looking at the surface from a different point in space surf (X,Y,Z,'FaceColor','red','EdgeColor','none'); camlight left; lighting phong view (-15,65) 16