Intro To MATLAB CS 534 - Fall 2013 Zach Welch. Overview ●Basics ●MATLAB data structures ●Operations ●Useful functions ●Image Processing and other useful.

Slides:



Advertisements
Similar presentations
Introduction to Matlab
Advertisements

1 EMT 101 – Engineering Programming Dr. Farzad Ismail School of Aerospace Engineering Universiti Sains Malaysia Nibong Tebal Pulau Pinang Week 10.
Introduction to Matlab Workshop Matthew Johnson, Economics October 17, /13/20151.
MATLAB – What is it? Computing environment / programming language Tool for manipulating matrices Many applications, you just need to get some numbers in.
Introduction to MATLAB and image processing. MATLAB and images The help in MATLAB is very good, use it! An image in MATLAB is treated as a matrix Every.
MATLAB for Image Processing April 10 th, Outline Introduction to MATLAB –Basics & Examples Image Processing with MATLAB –Basics & Examples.
Introduction to Matlab By: Dr. Maher O. EL-Ghossain.
Lecture 6 Sept 15, 09 Goals: two-dimensional arrays matrix operations circuit analysis using Matlab image processing – simple examples.
Laboratory of Image Processing Pier Luigi Mazzeo November 4 th, 2014.
MATLAB for Image Processing CS638-1 TA: Tuo Wang Feb 12 th, 2010.
Martin Ellison University of Warwick and CEPR Bank of England, December 2005 Introduction to MATLAB.
Nonparametric Econometrics1 Intro to Matlab for Data Analysis and Statistical Modeling.
Introduction to Matlab 1. Outline: What is Matlab? Matlab Screen Variables, array, matrix, indexing Operators Plotting Flow Control Using of M-File Writing.
Introduction to MATLAB. Windows in MATLAB Command Window – where you enter data, run MATLAB code, and display results Command History - displays a log.
Introduction to MATLAB
MATLAB Tutorial EE 327 Signals and Systems 1. What is MATLAB? MATLAB – Matrix Laboratory The premier number-crunching software Extremely useful for signal.
What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation tools. Others include Maple Mathematica MathCad.
MATLAB Practice 1 Introducing MATLAB Lecture Notes on Video Search & Mining, Spring 2012 Presented by Jun Hee Yoo Biointelligence Laboratory School of.
CS112 Scientific Computation Department of Computer Science Wellesley College Numb3rs Number and image types.
Matlab The language of Technical computing Mr. D. Suresh Assistant Professor, Dept. of CSE, PSNA CET, Dindigul.
Getting Started with MATLAB CS534 TA: Matt McDaniel Sep 17 th, 2012 Slides by Chunhui Zhu – Fall 2011 Thanks to the help from Tuo.
OUTLINE Overview Numbers, variables and similar in Matlab
Lecture 20: Choosing the Right Tool for the Job. What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation.
Lecture 26: Reusable Methods: Enviable Sloth. Creating Function M-files User defined functions are stored as M- files To use them, they must be in the.
Digital Image Processing Lecture 6: Introduction to M- function Programming.
Digital Image Processing Introduction to M-function Programming.
Outline Introduction to MATLAB Image Processing with MATLAB
CIS 601 Fall 2003 Introduction to MATLAB Longin Jan Latecki Based on the lectures of Rolf Lakaemper and David Young.
Digital Image Processing Introduction to MATLAB. Background on MATLAB (Definition) MATLAB is a high-performance language for technical computing. The.
Introduction to MATLAB 1.Basic functions 2.Vectors, matrices, and arithmetic 3.Flow Constructs (Loops, If, etc) 4.Create M-files 5.Plotting.
Lecture 27: Image Processing
Math 252: Math Modeling Eli Goldwyn Introduction to MATLAB.
Introduction to MATLAB Ehsan Adeli M. Iran University of Science and Technology, E-Learing Center, Fall 2008 (1387)
Graphics and Image Data Representations 1. Q1 How images are represented in a computer system? 2.
Introduction to MATLAB CS 534 Fall What you'll be learning today ●MATLAB basics (debugging, IDE) ●Operators ●Matrix indexing ●Image I/O ●Image display,
Introduction to Matlab. Outline:  What is Matlab? Matlab Screen Variables, array, matrix, indexing Operators.
Computer Application in Engineering Design
Getting Started with MATLAB
Matlab Programming for Engineers
ECE 1304 Introduction to Electrical and Computer Engineering
Prof. Mark Glauser Created by: David Marr
L – Modeling and Simulating Social Systems with MATLAB
Lecture: MATLAB Chapter 1 Introduction
Other Kinds of Arrays Chapter 11
Other Kinds of Arrays Chapter 11
Introduction to MATLAB
Introduction to MATLAB
INTRODUCTION TO BASIC MATLAB
MATLAB DENC 2533 ECADD LAB 9.
Matlab Workshop 9/22/2018.
MATLAB: Structures and File I/O
L – Modelling and Simulating Social Systems with MATLAB
Introduction to MATLAB
StatLab Matlab Workshop
Digital Image Processing using MATLAB
Introduction to MATLAB
MATLAB (Lecture 2) BY:MAHA ALMOUSA.
Use of Mathematics using Technology (Maltlab)
MATLAB Tutorial Dr. David W. Graham.
StatLab Workshop: Intro to Matlab for Data Analysis and Statistical Modeling 11/29/2018.
Matlab tutorial course
Lecture 2 Introduction to MATLAB
PHP.
Announcements P3 due today
Simulation And Modeling
Matlab Training Session 2: Matrix Operations and Relational Operators
MATLAB stands for MATrix LABoratory.
Comparing Python and Java
MATLAB (Lecture 2) BY:MAHA ALMOUSA.
Introduction to Image Processing with MATLAB
Presentation transcript:

Intro To MATLAB CS Fall 2013 Zach Welch

Overview ●Basics ●MATLAB data structures ●Operations ●Useful functions ●Image Processing and other useful things for 534 ●Demo ●Q&A

Accessing MATLAB ●MATLAB is available on the Linux and Windows labs ●On Linux, type “matlab” into the terminal ●Can remotely access via ssh

MATLAB Basics ●Short for MATrix LABoratory ●High level, interpreted language ●Great for data heavy applications “MATLAB is an interactive, matrix-based system for scientific and engineering numeric computation and visualization. You can solve complex numerical problems in a fraction of the time required with a programming Language such as Fortran or C.” ---- MATLAB Primer

MATLAB IDE COMMAND WINDOW Where you type commands Workspace List of your current variables Command History List of previous commands Current Path Filespace

Matrices ●Building a Matrix ○ Explicitly A = [1 2 3 ;4 5 6;7 8 9] ○ Using a Function B = eye(2,3) ■ zeros,ones,rand ●Accessing Elements ○ Matrix indices start at 1,*NOT 0* ○ A(1,2) ->

Matrix Operations ●+Addition ●-Subtraction ●*Matrix Multiplication ●^ Matrix Power ●‘Transpose ●\Left Matrix Division (Solves A*x=B) ●/Right Matrix Division (Solves x*A=B) ●.*Element by Element Multiplication ●./Element by Element Division ●.^ Element by Element Power ●sizeget matrix dimensions ●:access a subset of indices

How Operations Work B = A = A+B = A-B = A*B = A^2 = solves A*x = B A/B = A\B = solves x*A = B

How Per-Element Operations Work A.* B = A.*/ B = A.*^ B = B = A = C = C’ =

Size B = size(B,1) = 3 size(B,2) = 2 [row,col] =size(B) row => 3 col => 2 FUNCTIONS CAN RETURN MULTIPLE ARGUMENTS IN MATLAB Size gets the dimensions of the matrix. size(Matrix, DIM) DIM = 1 -> get row dimension DIM = 2 -> get column dimension

Colon Operator (:) ●Extremely useful operator ○ Generates an array of evenly spaced numbers in a user specified range ●start : increment : stop ●if increment is left out, assumed to be one

Colon Operator (:) ●Used to efficiently access submatrices ○ using no numbers -> all elements in dimension A = A(:,1) = A(2:end,1) = A(1:2:end, 2:2:end) =

●Logical Operators ○ ==is equal to ○, =less/greater than ○ ~not ○ ~=not equal to ●Instead of using brackets, MATLAB uses “end” Flow Control for(int a=0;a<=10;a++){ if( a>3){... … } C for (a=0:10) if (a>3)... … end MATLAB

Flow Control : IF ●If statements in MATLAB are very similar to if statements in other languages ●Notice elseif is one word if (boolean) … elseif (boolean) … else … end

Flow Control : WHILE ●while statements in MATLAB are very similar to while statements in other languages while (boolean)... end

●For is most different from other languages ●Cannot infinite loop in a for loop ●Uses : operator ○ start : increment : stop Flow Control : FOR if(start < stop){ if(inc>0){ for(a=start;a<=stop;a+=inc){ … } else{ if(inc<0){ for(a=start;a>=stop;a+=inc){ … } C for (a=start:inc:stop) … end MATLAB

It seems like I can use these loops as I do in C/C++/Java… Try to AVOID THIS!

Time Cost Comparison Loop vs. No Loop A = rand(1000,1000);B = rand(1000,1000); for i = 1:size(A,1), for j = 1:size(A,2), C(i,j) = A(i,j) + B(i,j); end Using loop: Elapsed time is seconds.

Time Cost Comparison(cont.) Loop vs. no loop C = A + B Elapsed time is seconds. Try to take advantage of matrix/vector structure whenever possible

Useful Functions ●“;” - Suppress output ●who - List current variables ●help - get information on a function ●lookfor - keyword search all function help info ●clear - delete all variables

Writing MATLAB functions ●Matlab code is saved in.m files ●2 kinds of.m files ○ Function.m files ■ Contain a function definition ■ One function per file ■ FILE NAME MUST MATCH FUNCTION NAME ○ Script.m files ■ Contain a list of commands ■ Can be named anything ■ Often used as drivers for functions you have implemented ● Kind of like main in other languages

Writing MATLAB functions ●Structure of a MATLAB function ●Functions Can Return Multiple values ●Make sure you initialize your return variables function returnVal = FunctionName (input1,input2) %Adds two numbers returnVal = input1+input2; end function [return1, return2] = FunctionName (input1,input2) return1 = input1+input2; return2= 0; end

MATLAB can import/export several image formats: –BMP (Microsoft Windows Bitmap) –GIF (Graphics Interchange Files) –HDF (Hierarchical Data Format) –JPEG (Joint Photographic Experts Group) –PCX (Paintbrush) –PNG (Portable Network Graphics) –TIFF (Tagged Image File Format) –XWD (X Window Dump) –raw-data and other types of image data Data types in MATLAB –Double (64-bit double-precision floating point) –Single (32-bit single-precision floating point) –Int32 (32-bit signed integer) –Int16 (16-bit signed integer) –Int8 (8-bit signed integer) –Uint32 (32-bit unsigned integer) –Uint16 (16-bit unsigned integer) –Uint8 (8-bit unsigned integer) Images In MATLAB

Column 1 to 256 Row 1 to 256 o [1, 1] o [256, 256] How to build a matrix (or image)? Intensity Image: row = 256; col = 256; img = zeros(row, col,3); img(100:105, :,1) = 0.5; img(:, 100:105,2) = 1; imshow(img); Images In MATLAB

Image Processing Functions ●img = imread(imageFileName) - reads in an image file (.jpg,.png,etc) and returns : ○ [width,height] sized matrix if grayscale ○ [width,height,3] sized matrix if rgb ●imshow(img) - display an image ●img = im2double(img) - Converts an image (which may be uint8[0- 255] or double[ ]) to double[ ] ●im2uint8 ●imwrite(img,FileName,fileType) - write out an image ●Basic structure is: img = imread(‘input.jpg’); imshow(img); %Do something to the image imshow(img); imwrite(img,’output.jpg’,’jpg’);

Questions?

Demos