Matlab Primer. Lecture 02a Optical Sciences 330 Physical Optics II William J. Dallas January 12, 2005

Similar documents
Introduction to Matlab

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

Image Processing Matlab tutorial 2 MATLAB PROGRAMMING

1 Overview of the standard Matlab syntax

Digital Image Processing

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

Introduction to Matlab

Chapter 1 Introduction to MATLAB

Introduction to MATLAB

CM0340 Tutorial 2: More MATLAB

Introduction to MATLAB

Eng Marine Production Management. Introduction to Matlab

Compact Matlab Course

ECE Lesson Plan - Class 1 Fall, 2001

Introduction to Matlab

CS1114: Matlab Introduction

Introduction to MATLAB

2.0 MATLAB Fundamentals

MATLAB Introductory Course Computer Exercise Session

CS1114: Matlab Introduction

MAT 343 Laboratory 1 Matrix and Vector Computations in MATLAB

function [s p] = sumprod (f, g)

An Introduction to MATLAB

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.

Getting started with MATLAB

THE BARE ESSENTIALS OF MATLAB

An Introduction to MATLAB. Lab tutor : Dennis Yang LIU Lab 1: Sept. 11, 2014

EL2310 Scientific Programming

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

AN INTRODUCTION TO MATLAB

MATLAB BASICS. M Files. Objectives

A Guide to Using Some Basic MATLAB Functions

MatLab Just a beginning

Some elements for Matlab programming

AMATH 352: MATLAB Tutorial written by Peter Blossey Department of Applied Mathematics University of Washington Seattle, WA

CS 221 Lecture. Tuesday, 4 October There are 10 kinds of people in this world: those who know how to count in binary, and those who don t.

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

Matlab Tutorial: Basics

TUTORIAL 1 Introduction to Matrix Calculation using MATLAB TUTORIAL 1 INTRODUCTION TO MATRIX CALCULATION USING MATLAB

MAT 343 Laboratory 1 Matrix and Vector Computations in MATLAB

Unix Computer To open MATLAB on a Unix computer, click on K-Menu >> Caedm Local Apps >> MATLAB.

MATLAB for beginners. KiJung Yoon, 1. 1 Center for Learning and Memory, University of Texas at Austin, Austin, TX 78712, USA

MATLAB GUIDE UMD PHYS401 SPRING 2012

Matlab (Matrix laboratory) is an interactive software system for numerical computations and graphics.

CITS2401 Computer Analysis & Visualisation

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

Matlab for FMRI Module 1: the basics Instructor: Luis Hernandez-Garcia

Finding MATLAB on CAEDM Computers

University of Alberta

MATLAB = MATrix LABoratory. Interactive system. Basic data element is an array that does not require dimensioning.

TUTORIAL MATLAB OPTIMIZATION TOOLBOX

EL2310 Scientific Programming

Introduction to MATLAB

Introduction to Octave/Matlab. Deployment of Telecommunication Infrastructures

Introduction to MATLAB. Recommended bibliography. Need more help? Session 1. Getting started.

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

MATLAB. Devon Cormack and James Staley

Computational Mathematics

Digital Image Analysis and Processing CPE

How to Use MATLAB. What is MATLAB. Getting Started. Online Help. General Purpose Commands

Matlab and Octave: Quick Introduction and Examples 1 Basics

Introduction to Matlab

xv Programming for image analysis fundamental steps

Pace University. Fundamental Concepts of CS121 1

CS100R: Matlab Introduction

MATLAB SUMMARY FOR MATH2070/2970

Eric W. Hansen. The basic data type is a matrix This is the basic paradigm for computation with MATLAB, and the key to its power. Here s an example:

ECE 3793 Matlab Project 1

Math 98 - Introduction to MATLAB Programming. Fall Lecture 1

Lecture 1: Hello, MATLAB!

To start using Matlab, you only need be concerned with the command window for now.

Outline. User-based knn Algorithm Basics of Matlab Control Structures Scripts and Functions Help

ENGR 253 LAB #1 - MATLAB Introduction

Outline. CSE 1570 Interacting with MATLAB. Outline. Starting MATLAB. MATLAB Windows. MATLAB Desktop Window. Instructor: Aijun An.

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.

What is MATLAB and howtostart it up?

Introduction and MATLAB Basics

INTRODUCTION TO MATLAB, SIMULINK, AND THE COMMUNICATION TOOLBOX

HERIOT-WATT UNIVERSITY DEPARTMENT OF COMPUTING AND ELECTRICAL ENGINEERING. B35SD2 Matlab tutorial 1 MATLAB BASICS

Image Processing CS 6640 : An Introduction to MATLAB Basics Bo Wang and Avantika Vardhan

Outline. CSE 1570 Interacting with MATLAB. Starting MATLAB. Outline. MATLAB Windows. MATLAB Desktop Window. Instructor: Aijun An.

A Very Brief Introduction to Matlab

Introduction to Matlab. By: Hossein Hamooni Fall 2014

Constraint-based Metabolic Reconstructions & Analysis H. Scott Hinton. Matlab Tutorial. Lesson: Matlab Tutorial

Introduction to MATLAB

Computer Vision, Laboratory session 1

EE3TP4: Signals and Systems Lab 1: Introduction to Matlab Tim Davidson Ext Objective. Report. Introduction to Matlab

Desktop Command window

Matlab? Chapter 3-4 Matlab and IPT Basics. Working Environment. Matlab Demo. Array. Data Type. MATLAB Desktop:

Introduction to MATLAB

Introduction to MATLAB

MATLAB. Miran H. S. Mohammed. Lecture 1

1 Introduction to Matlab

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

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

Brief Matlab tutorial

SECTION 5: STRUCTURED PROGRAMMING IN MATLAB. ENGR 112 Introduction to Engineering Computing

Introduction to MatLab. Introduction to MatLab K. Craig 1

Starting with a great calculator... Variables. Comments. Topic 5: Introduction to Programming in Matlab CSSE, UWA

Transcription:

Matlab Primer Lecture 02a Optical Sciences 330 Physical Optics II William J. Dallas January 12, 2005

Introduction The title MATLAB stands for Matrix Laboratory. This software package (from The Math Works, Inc.) is designed specifically to perform operations on matrices. The package consists of a command interpreter, a command language and a collection of routines which can be exercised by the interpreter. The commands can either be entered line-by-line in the command window or they can be collected in a text file to be executed by a single line entered in the command window. All computations internal to MATLAB are done in double precision.

Inline Help To access the inline help, type help in the command window followed by the term in question. For example, if you wish to find out the syntax of the IF statement, you can type help if on the command line. A brief explanation will then appear in the command window.

HTML Help To access the html help, select Help on the menu-bar of the main Matlab window, then select MATLAB help. Alternatively, you can press the F1 function key on your keyboard.

Scripts or M-files MATLAB programs can be typed in lineby-line at the command prompt. M-file: type the commands line-by-line into a text file, using for instance the Matlab editor, saving to a script file. At the command prompt, type the name of the file or press the run button on the Matlab editor toolbar. A comment can be inserted by beginning a line with the percent (%) character.

Search Path Matlab will find M-files only if the reside on the current directory, or are listed in your search path. You can examine and modify your search path by selecting File on the main Matlab menu bar, then selecting Set Path.

Variables All variables are matrices. Scalars are 1 x 1 matrices; vectors are 1 x N or N x 1 matrices. The matrices may be of type real, complex, or string. Note that variable names are case sensitive. There are two special matrices we will use often, the matrix of dimensions M x N that is filled with zeroes or ones: zeros(m,n) filled with zeroes ones(m,n) filled with ones

Operators I Assignment = Assign the value on the right to the variable on the left. Semicolon The semicolon is very important, though not strictly an operator. It suppresses the echo of entries to the command screen. For example, suppose you assign a large matrix to second, equally large, matrix. Unless you enter a semicolon on the line after the assignment, all of all of matrix values will be written to the screen. Should this happen, you can interrupt the operation by hitting CNTRL_C.

Operators II The arithmetic binary operators, operators that combine two variables, exist in MATLAB as two families: the matrix operators and the array operators. Arithmetic Operators of Identical Matrix and Array Form + addition - subtraction

Arithmetic Matrix-Operators * multiplication / right division \ left division ^ raising to a power ' transpose with conjugate

Arithmetic Array-Operators.* multiplication./ right division.\ left division.^raising to a power.' transpose with no conjugate

Relational Operators < less than > greater than <= less than or equal to >= greater than or equal to == equal to ~= not equal to

Flow-Control Structures I Loop While: Repeats the group of statements within the command's scope while the condition contained in the control variable is true. For: Repeats the group of statements within the command's scope for a specific number of times End: Delimits the scope of a "FOR" or "WHILE" statement Break: Terminates the execution of a loop.

Flow-Control Structures II Branch If: Conditionally executes a group of statements within the command's scope depending on the logical value of the control expression. Elseif: Specifies an alternative action when the "IF" control variable is false and the "ELSEIF" control variable is true. Else: Specifies an alternative action when the "IF" control variable is false and (if present) the "ELSEIF" control variable is false. End: Delimits the scope of an "IF" statement. Return: Return control to the invoking function.

Input/Output Commands Interactive Input Graphical Output

Interactive Input Input: Displays the prompt in the text string on the command screen and then waits for input from the keyboard. Menu: Generates a menu of choices for user input. Pause: Stops execution and waits for a user response, or the elapsing of a timer. Keyboard: Invoke the keyboard as if it were a Script-file.

Disk Commands I Directory Commands The directory commands available in MATLAB are identical to those in DOS. For instance, the command "dir" lists the files present on your current directory. The command "c:" will change your present directory to the C disk. The command "cd" will change your directory. Save The form most useful to us will be "save file_name variable_name". This command will save "variable_name" to disk in the file "file_name" with the extension "mat" located on your current directory.

Disk Commands II Load The "load" command retrieves variables from disk. The form most useful is "load file_name". The expression "file_ name" is the name of a file with the extension "mat". Imwrite Write an image in a given format. The formats can, among others, be bmp, jpg, tif, pcx, pgm, png, or ppm. Imread Read an image in a given format. See Imwrite for some of the formats.

Maxima and Minima Finding extrema will be of immediate importance to us in normalizing matrices for display. These functions determine the vector y in a matrix x, or scalar y in a vector x containing the extremum: y = max(x); maximum over the columns y = min(x); minimum over the columns More usually we wish to have the scalar y containing the extremum in a matrix x: y = max(max(x)); maximum over the entire matrix y = min(min(x)); minimum over the entire matrix

Fourier Transforms There are three steps in doing a discrete Fourier transform or DFT: quadrant-swap, FFT, quadrant-swap The quadrant swapping routine is the same for all dimensions, but the FFT routine differs for one and two dimensions. We assume an array x of the appropriate dimensionality. Complete 2-D FFT: y = fftshift(fft2(fftshift(x))); Complete 2-D inv. FFT: y = fftshift(ifft2(fftshift(x)));

Displaying an Image I To open figure window number one, or to select it if it is already open figure (1); For monochrome images your set a graytone color map from 0-63 with colormap(gray); Alternate 256-level colormap: Generate: Ramp = (0:255)/255.0; Gray256 = zeros(256,3); Gray256(:,1)=Ramp; Gray256(:,2)=Ramp;Gray256(:,3)=Ramp; Load: colormap(gray256 );

Displaying an Image II If the data you wish to display are contained in the array "MyImage" and the values have been normalized to the depth of your color table you may use image (x); If the data you wish to display are contained in the variable " MyImage " and wish to let Matlab take care of the gray-scaling imagesc (MyImage); To close figure 1 close (1);

Manipulating the Workspace To show the variables and their storagespace allocations in the workspace whos To clear the workspace clear

Examples in the Lecture Notes Matrix filling Control-flow structure

Always Comment your code Name yourself as author, give credit if the code is derived from another source Put the date latest revision in your code