Introduction to Matlab

Similar documents
Table of Contents. Introduction.*.. 7. Part /: Getting Started With MATLAB 5. Chapter 1: Introducing MATLAB and Its Many Uses 7

Computing Fundamentals Plotting

CHAPTER 1 Graphics Systems and Models 3

A Guide to Using Some Basic MATLAB Functions

Plotting - Practice session

MATLAB 7 Getting Started Guide

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

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.

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

INTRODUCTION TO MATLAB

AN INTRODUCTION TO MATLAB

Finding, Starting and Using Matlab

LAB 1 General MATLAB Information 1

UNIVERSITI TEKNIKAL MALAYSIA MELAKA FAKULTI KEJURUTERAAN ELEKTRONIK DAN KEJURUTERAAN KOMPUTER

LAB 1: Introduction to MATLAB Summer 2011

Session 3 Introduction to SIMULINK

Lab of COMP 406. MATLAB: Quick Start. Lab tutor : Gene Yu Zhao Mailbox: or Lab 1: 11th Sep, 2013

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

! The MATLAB language

Introduction to MATLAB

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

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

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

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

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

MATLAB 7. The Language of Technical Computing KEY FEATURES

Lecturer: Keyvan Dehmamy

Introduction to MATLAB

Graphics and GUIs. with MATLAB THIRD EDITION by Chapman & Hall/CRC

1-- Pre-Lab The Pre-Lab this first week is short and straightforward. Make sure that you read through the information below prior to coming to lab.

A/D Converter. Sampling. Figure 1.1: Block Diagram of a DSP System

1 Introduction to Matlab

STEPHEN WOLFRAM MATHEMATICADO. Fourth Edition WOLFRAM MEDIA CAMBRIDGE UNIVERSITY PRESS

Matlab Tutorial. Get familiar with MATLAB by using tutorials and demos found in MATLAB. You can click Start MATLAB Demos to start the help screen.

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

GRAPHICS AND VISUALISATION WITH MATLAB Part 2

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

Introduction to MATLAB

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

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

A MATLAB Exercise Book. Ludmila I. Kuncheva and Cameron C. Gray

print and printopt produce hardcopy output. All arguments to the print command are optional. You can use them in any combination or order.

ECE Lesson Plan - Class 1 Fall, 2001

Introduction to MATLAB Programming

Dr Richard Greenaway

Dr Richard Greenaway

PROGRAMMING AND ENGINEERING COMPUTING WITH MATLAB Huei-Huang Lee SDC. Better Textbooks. Lower Prices.

Matlab Introduction. Scalar Variables and Arithmetic Operators

Programming in Mathematics. Mili I. Shah

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

MATLAB/Octave Tutorial

UNIVERSITI TEKNIKAL MALAYSIA MELAKA FAKULTI KEJURUTERAAN ELEKTRONIK DAN KEJURUTERAAN KOMPUTER

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

Physics 251 Laboratory Introduction to Spreadsheets

Getting Started with MATLAB

Introduction to Matlab. By: Hossein Hamooni Fall 2014

Essential MATLAB for Engineers and Scientists

MATLAB Functions and Graphics

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

Introduction to MATLAB Practical 1

MATLAB Programming for Numerical Computation Dr. Niket Kaisare Department Of Chemical Engineering Indian Institute of Technology, Madras

MATLAB Basics. Configure a MATLAB Package 6/7/2017. Stanley Liang, PhD York University. Get a MATLAB Student License on Matworks

STAT/MATH 395 A - PROBABILITY II UW Winter Quarter Matlab Tutorial

George Mason University Signals and Systems I Spring 2016

Chapter 2. MATLAB Fundamentals

What is Matlab? A software environment for interactive numerical computations

University of Alberta

Lecture 1: What is MATLAB?

General MATLAB Information 1

SAS Visual Analytics 8.2: Working with Report Content

Experiment 1: Introduction to MATLAB I. Introduction. 1.1 Objectives and Expectations: 1.2 What is MATLAB?

Laboratory 1 Octave Tutorial

Introduction to MatLab. Introduction to MatLab K. Craig 1

Mathworks (company that releases Matlab ) documentation website is:

PART 1 PROGRAMMING WITH MATHLAB

Introduction to MATLAB

Lecture 2: Variables, Vectors and Matrices in MATLAB

Stokes Modelling Workshop

A Brief Introduction to MATLAB Evans Library Research Support Workshops

Introduction to Matlab. By: Dr. Maher O. EL-Ghossain

Lab 1 Introduction to MATLAB and Scripts

Why use MATLAB? Mathematcal computations. Used a lot for problem solving. Statistical Analysis (e.g., mean, min) Visualisation (1D-3D)

Introduction to Matlab

2.0 MATLAB Fundamentals

Huei-Huang Lee. Programming with MATLAB2016 SDC ACCESS CODE. Better Textbooks. Lower Prices. UNIQUE CODE INSIDE

Introduction to Octave/Matlab. Deployment of Telecommunication Infrastructures

Introduction to MATLAB

Mathematics 6 12 Section 26

PROGRAMMING WITH MATLAB WEEK 6

Getting started with MATLAB

A very brief Matlab introduction

Introduction to Matlab

3D plot of a surface in Matlab

Introduction to Matlab. Summer School CEA-EDF-INRIA 2011 of Numerical Analysis

Introduction to MATLAB LAB 1

Contents. Table of Contents. Table of Contents... iii Preface... xvii. Getting Started iii

MAT 343 Laboratory 1 Matrix and Vector Computations in MATLAB

selected topic in transportation 2552/2. 1 Prepared by Lect.Weerakaset Suanpaga

Starting MATLAB To logon onto a Temple workstation at the Tech Center, follow the directions below.

Transcription:

Introduction to Matlab Matlab (MATrix LABoratory) will be the programming environment of choice for the numerical solutions developed in this textbook due to its wide availability and its ease of use. Matlab provides an interactive screen where commands can be typed and where the software returns output from those commands. The figure below shows the Matlab interactive environment for an earlier Student Edition of the software. The cursor is shown in this figure in front of the Matlab prompt, in this case, EDU>>. One can type commands in front of the prompt and then press the <Enter> key to activate the command and obtain an output from Matlab. For example, Matlab can be used as a calculator to obtain the value of the following expression 2 3 4 12.5 by typing the following statement at the prompt: (2+3/4)/sqrt(12.5) Matlab replies with the following output: ans = 0.7778

This results indicates that Matlab calculated the numerical result of the expression typed and stored that value in a variable named ans (answer). Matlab then showed the contents of variable ans in the interactive window. Please notice that Matlab will replace the contents of variable ans with the most recent result everytime that a calculation is performed in the Matlab window. To verify this statement, try the following calculations in Matlab (remember to press <Enter> after each entry): (5+3/4)^2.3/sqrt(5+1/3) sin(2*pi/3) log(2.3+sqrt(4.2)) These examples illustrate a few interesting facts about Matlab: 1. The fundamental arithmetic operation symbols are +, -, *, and / 2. To raise a number or expression to a power use the caret symbol ^ 3. The ratio of the length of a circle to its diameter, typically referred to as π, is available by typing pi. 4. Many classical mathematical functions such as the trigonometric functions sine (sin), cosine (cos), tangent (tan), tand he natural logarithm (log) and exponential (exp) functions are available for calculations. A few other important issues about using Matlab are listed next: 1. The Edit menu includes the options Undo, Copy, Cut, and Paste for editing expressions in the Matlab window. In Windows-based systems, you can also use Cntl-C and Cntl-V to copy and paste. 2. If you have to type a very long expression that requires two or more lines in the Matlab window, you can use the continuation characters (...) to specify the command, for example: EDU» (2.5+3.5*pi+1/log(2.3+sqrt(1.2)))/... (2.3+sin(3*pi/7)-1/2) ans = 5.1582 3. The Help menu contains several options for finding information about Matlab functions or commands. The option Help Tips provides information on the use of the Help facility. The option Help window produces a text window listing various chapters of help entries grouped according to certain subjects (see figure below). Double-click on any of the chapters to access a listing of functions contained in that chapter. Double click on any of the functions listed to get a help entry on that function. For example, find the help entry for function plot3 in the help chapter entitled Matlab\graph3d.

The option Examples and Demos in the Help menu activates a Matlab dialog box showing a number of applications of Matlab in various fields of mathematics (see first figure below). Click on the titles shown in the left frame of the dialog box to select a specific collection of examples. Click on a specific application title in the field at the bottom of the dialog box to select that particular example. Press the Run button to activate the demonstration. Typically, there will be a new dialog box open with an output figure and a field listing the Matlab commands needed to produce the given result. The option Help Desk(HTML) in the Help menu activates an html document (a web page) that contains information about the operation of Matlab (see figure below). Click on the link Documentation Roadmap to get an overall view of the Help Desk contents. Click on the link Getting Started to get an overview of Matlab's operation for mathematical calculations and graphics. The frame to the left in the Getting Started web page provides an outline of the page contents. Dedicate some time to explore the different chapters thus contained. These chapters and subchapters contain definitions and examples to help you learn the use of Matlab.

Using the Help Desk to learn about the Matlab environment This sections offer guidelines on using the Help Desk to learn the basics about the Matlab environment. Open the Help Desk web page as described above. Click on the link Matlab Environment and follow the outline of the page contents shown in the left-hand field. Click on the links in the contents field to see examples and exercises for any particular section. It is recommended that you read the contents of the Matlab Environment web page while running Matlab so you can reproduce the exercises shown in the Help Desk. To facilitate trying the exercises in your own Matlab window, simply copy the commands listed in the Help Desk and paste them in your command window. Read the Matlab Environment web page in detail to learn the basic operation of the Command Window, the Editor, and the Figure windows (used to produce graphics). Using the Help Desk to learn Matlab operation This sections offer guidelines on using the Help Desk to learn the use of Matlab on your own. Open the Help Desk web page as described earlier. Click on the link Getting Started and follow the outline of the page contents shown in the left-hand field. Click on the links in the contents field to see examples and exercises for any particular section. It is recommended that you read the contents of the Getting Started web page while running Matlab so you can reproduce the exercises shown in the Help Desk. To facilitate trying the exercises in your own Matlab window, simply copy the commands listed in the Help Desk and paste them in your command window. Since the Getting Started page contains a large variety of concepts and examples, it is recommended that you take a few days to go over all of them while trying the corresponding exercises. The following schedule of reading is recommended based on the amount of material and on the contents of the outline. You may want to keep a notebook handy to summarize the most important commands you learn while reading the Help Desk pages. Day 1 Introduction Introduction What Is MATLAB? The MATLAB System About Simulink Getting Started Starting MATLAB Matrices and Magic Squares Entering Matrices sum, transpose, and diag

Subscripts The Colon Operator The magic Function Expressions Variables Numbers Operators Functions Expressions Working with Matrices Generating Matrices load M-Files Concatenation Deleting Rows and Columns Day 2 Command window/graphics The Command Window The format Command Suppressing Output Long Command Lines Command Line Editing Graphics Creating a Plot Figure Windows Adding Plots to an Existing Graph Subplots Imaginary and Complex Data Controlling Axes Axis Labels and Titles Mesh and Surface Plots Visualizing Functions of Two Variables Images Printing Graphics Day 3 Help / Matlab environment Help and Online Documentation The help Command The Help Window The lookfor Command The Help Desk The doc Command Printing Online Reference Pages Link to the MathWorks

The MATLAB Environment The Workspace save Commands The Search Path Disk File Manipulation The diary Command Running External Programs Day 4 Matrices / Arrays More About Matrices and Arrays Linear Algebra Arrays Multivariate Data Scalar Expansion Logical Subscripting The find Function Day 5 - Flow control Flow Control if switch and case for while break Day 6 - Data/Scripts/Functions Other Data Structures Multidimensional Arrays Cell Arrays Characters and Text Structures Scripts and Functions Scripts Functions Global Variables Command/Function Duality The eval Function Vectorization Preallocation Function Functions Day 7 Handle graphics Handle Graphics Graphics Objects Graphics Objects

Object Handles Object Creation Functions Object Properties set and get Graphics User Interfaces Animations Movies Learning More Using the Help Desk to learn about Matlab graphics This sections offer guidelines on using the Help Desk to learn the use of Matlab graphics on your own. While some examples of graphics were presented in the contents of the Getting Started page, more detailed exampls on graphics are presented in the page entitled Using Matlab graphics. Open the Help Desk web page as described in an earlier page. Click on the linkusing Matlab Graphics and follow the outline of the page contents shown in the left-hand field. Click on the links in the contents field to see examples and exercises for any particular section. The following schedule of reading is recommended based on the amount of material and on the contents of the outline. Day 1 Introduction Introduction High-Level Graphics Handle Graphics Building Interactive GUIs How It All Fits Together Where to Begin Basic Plotting Basic Plotting Commands Creating Plots Specifying Line Style Specifying the Color and Size of Lines Adding Plots to an Existing Graph Plotting Only the Data Points Plotting Markers and Lines Line Styles for Black and White Output Setting Default Line Styles Day 2 Line plots / Figure windows Line Plots of Matrix Data Plotting Imaginary and Complex Data Plotting with Two Y-Axes

Line Plots of 3-D Data Setting Axis Parameters Axis Limits and Ticks Example - Specifying Ticks and Tick Labels Setting Aspect Ratio Figure Windows Displaying Multiple Plots per Figure Specifying the Target Axes Default Color Scheme Day 3 Labeling graphs Labeling Graphs Labeling Individual Axes Adding Text Strings to a Graph Positioning Text on Graphs Text Alignment Specifying TeX Characters Using Variables in Text Strings Example - Aligning Text Example - Multiline Text Day 4 - Specialized graphs Specialized Graphs Bar and Area Graphs Types of Bar Graphs Stacked Bar Graphs to Show Contributing Amounts Specifying X-Axis Data Overlaying Plots on Bar Graphs Area Graphs Comparing Datasets with Area Graphs Pie Charts Removing a Piece from a Pie Charts Histograms Histograms in Cartesian Coordinate Systems Histograms in Polar Coordinate Systems Specifying Number of Bins Day 5 Discrete / velocity data graphs Discrete Data Graphs Two-Dimensional Stem Plots Combining Stem Plots with Line Plots Three-Dimensional Stem Plots Stairstep Plots Direction and Velocity Vector Graphs

Compass Plots Feather Plots Two-Dimensional Quiver Plots Three-Dimensional Quiver Plots Day 6 Contour / interactive plots Contour Plots Creating Simple Contour Plots Labeling Contours Filled Contours Drawing a Single Contour Line at a Desired Level The Contouring Algorithm Changing the Offset of a Contour Displaying Contours in Polar Coordinates Interactive Plotting Animation Movies Erase Modes Day 7 Three dimensional graphs Creating 3-D Graphs Representing a Matrix as a Surface Mesh and Surface Plots Visualizing Functions of Two Variables Surface Plots of Nonuniformly Sampled Data Parametric Surfaces Hidden Line Removal Coloring Mesh and Surface Plots Colormaps Indexed Colors - Direct and Scaled Colormapping Example - Mapping Surface Curvature to Color Altering Colormaps Truecolor Texture Mapping Day 8 Defining the view Defining the View Setting the Viewpoint Defining Scenes with Camera Graphics Camera Graphics Commands Example - Dollying the Camera Example - Creating a Fly-Through Low-Level Camera Properties

Default Viewpoint Selection Moving In and Out on the Scene Making the Scene Larger or Smaller Revolving Around the Scene Rotation without Resizing of Graphics Objects Rotation About the Viewing Axis View Projection Types Projection Types and Camera Location Day 9 - Axes aspect ratio Understanding Axes Aspect Ratio Specifying Axis Scaling Specifying Aspect Ratio Example - axis Command Options Additional Commands for Setting Aspect Ratio Low-Level Aspect Ratio Properties Default Aspect Ratio Selection Overriding Stretch-to-Fill Effects of Setting Aspect Ratio Properties Example - Displaying Real Objects Day 10 - Lighting Lighting as a Visualization Tool Lighting Commands Light Objects Adding Lights to a Scene Properties that Affect Lighting Selecting a Lighting Method Reflectance Characteristics of Graphics Objects Specular and Diffuse Reflection Ambient Light Specular Exponent Specular Color Reflectance Back Face Lighting Positioning Lights in Data Space Day 11 Volume visualization Volume Visualization Techniques Volume Visualization Commands Visualizing Scalar Volume Data Example - Visualizing MRI Data Exploring Volumes with Slice Planes Example - Slicing Fluid Flow Data Modifying the Color Mapping

Connecting Equal Values with Isosurfaces Isocaps Add Context to Visualizations Defining Isocaps Visualizing Vector Volume Data Stream Line Plots of Vector Data Vector Data Displayed with Cone Plots Day 12 Patches in 3D Creating 3-D Models with Patches Behavior of the patch Function Creating a Single Polygon Multi-Faceted Patches Example - Defining a Cube Specifying Patch Coloring Face and Edge Coloring Example - Specifying Flat Edge and Face Coloring Coloring Edges with Shared Vertices How MATLAB Interprets Patch Color Data Indexed Color Data Truecolor Patches Interpolating in Indexed Color vs. Truecolor Day 13 Bit-mapped images Displaying Bit-Mapped Images Images in MATLAB Bit Depth Support Data Types Image Types Indexed Images Intensity Images RGB (Truecolor) Images Working with 8-Bit and 16-Bit Images 8-Bit and 16-Bit Indexed Images 8-Bit and 16-Bit Intensity Images 8-Bit and 16-Bit RGB Images Mathematical Operations Support for uint8 and uint16 Other 8-Bit and 16-Bit Array Support Summary of Image Types and Numeric Classes Reading, Writing, and Querying Graphics Image Files Reading a Graphics Image Writing a Graphics Image Obtaining Information About Graphics Files Displaying Graphics Images Summary of Image Types and Display Methods

Controlling Aspect Ratio and Display Size The Image Object and Its Properties CData CDataMapping XData and YData EraseMode Printing Images Converting the Data or Graphic Type of Images Day 14 Printing graphs Printing MATLAB Graphics Printing from the Menu PC UNIX Adjusting the Size and Color of the Graphic Print Preview Exporting Figures to Graphic Files Printing from the Command Line The print Command Passing String Arguments to print Changing Default Print Settings Graphic File Formats Output Formats Created by Ghostscript Specifying Command Line Options Tiff Preview for EPS (-tiff) Specifying the Bounding Box (-loose) CMYK Color Separations (-cmyk) Appending to an Existing File (-append) Specifying Resolution (-r) Default Character-Set Encoding (-adobecset) Specifying the Figure or Model to Print (-f, -s) Specifying the Printer to Use (-P) UNIX only Selecting an Output Format PostScript HPGL Compatible Plotters (-dhpgl) Adobe Illustrator 88 (-dill) PC-Specific Output Options Printing Lines and Text in Color or Black and White Specifying Fonts and Character Sets PC UNIX Specifying Line Styles Windows 95 Limitation Selecting the Rendering Method for Printing

Specifying the Rendering Method Size of Output Files Changing Background Colors Troubleshooting MS-Windows Printing Saving MATLAB Graphics in File Format MS-Windows Copy Options Importing MATLAB Graphics into Other Applications Selecting the Graphics File Format Vector Format Bitmap Format Additional Considerations Application-Specific Issues Including Graphics in Word Processor Documents Example - Importing a Graph Example - Importing a Bitmap Graphic Setting Figure Printing Properties Positioning the Figure on the Printed Page Example - Readjusting PaperPosition Specifying Paper Orientation Specifying Paper Size Reversing Figure Colors Day 15 Handle graphics Handle Graphics Graphics Objects Object Properties Graphics Object Creation Functions Example - Creating Graphics Objects Parenting High-Level Vs. Low-Level Simplified Calling Syntax Setting and Querying Property Values Setting Property Values Querying Property Values Factory-Defined Property Values Setting Default Property Values Defining Default Values Examples - Setting Default LineStyles Accessing Object Handles The Current Figure, Axes, and Object Searching for Objects by Property Values -- findobj Copying Objects Deleting Objects Controlling Graphics Output

Specifying the Target for Graphics Output Preparing Figures and Axes for Graphics Targeting Graphics Output with newplot Example - Using newplot Testing for Hold State Protecting Figures and Axes The Close Request Function Handle Validity versus Handle Visibility Saving Handles in M-files Properties Changed by Built-In Functions Day 16 Figure properties Figure Properties Positioning Figures Example -- Specifying Figure Position Controlling How MATLAB Uses Color Indexed Color Displays Colormap Colors and Fixed Colors Using a Large Number of Colors Nonactive Figures and Shared Colors Dithering Truecolor on Indexed Color Systems Selecting Drawing Methods Backing Store Double Buffering Selecting a Renderer Specifying the Figure Pointer Defining Custom Pointers Interactive Graphics Day 17 Axes properties Axes Properties Labeling and Appearance Properties Positioning Axes Units Multiple Axes per Figure Placing Text Outside the Axes Multiple Axes for Different Scaling Individual Axis Control Setting Axis Limits Setting Tick Mark Locations Changing Axis Direction Using Multiple X and Y Axes Automatic-Mode Properties Colors Controlled By Axes

Specifying Axes Colors Axes Color Limits - The CLim Property Example - Simulating Multiple Colormaps In a Figure Defining the Color of Lines for Plotting Line Styles Used for Plotting - LineStyleOrder Plotting and Visualization Functions