Introduction to MATLAB

Slides:



Advertisements
Similar presentations
Matlab Intro Simple introduction to some basic Matlab syntax. Declaration of a variable [ ] Matrices or vectors Some special (useful) syntax. Control statements.
Advertisements

MATLAB – A Computational Methods By Rohit Khokher Department of Computer Science, Sharda University, Greater Noida, India MATLAB – A Computational Methods.
1 A L L A H. Command-Window Workspace & Directory Command- History The Matlab Command window - Finding your way around.
Introduction to Matlab
MATLAB – What is it? Computing environment / programming language Tool for manipulating matrices Many applications, you just need to get some numbers in.
Image Display MATLAB functions for displaying image Bit Planes
CS231A Matlab Tutorial Philip Lee Winter Overview  Goals › Introduction to Matlab › Matlab Snippets › Basic image manipulations › Helpful Matlab.
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
EGR 106 – Week 2 – Arrays & Scripts Brief review of last week Arrays: – Concept – Construction – Addressing Scripts and the editor Audio arrays Textbook.
Introduction to MATLAB MECH 300H Spring Starting of MATLAB.
Introduction to Array The fundamental unit of data in any MATLAB program is the array. 1. An array is a collection of data values organized into rows and.
Computational Tools for Image Processing Lecture 1, Jan 22nd, 2007 Part 2 (8:10-9:20pm) by Lexing Xie EE4830 Digital Image Processing
Matlab intro The Environment
MATLAB Fundamentals.
1 MATLAB 基礎. 2 MATLAB  Workspace: environment (address space) where all variables reside  After carrying out a calculation, MATLAB assigns the result.
MATLAB for Image Processing CS638-1 TA: Tuo Wang Feb 12 th, 2010.
MATLAB INTRO CONTROL LAB1  The Environment  The command prompt Getting Help : e.g help sin, lookfor cos Variables Vectors, Matrices, and Linear Algebra.
Martin Ellison University of Warwick and CEPR Bank of England, December 2005 Introduction to MATLAB.
Engineering Analysis ENG 3420 Fall 2009 Dan C. Marinescu Office: HEC 439 B Office hours: Tu-Th 11:00-12:00.
Introduction to MATLAB January 18, 2008 Steve Gu Reference: Eta Kappa Nu, UCLA Iota Gamma Chapter, Introduction to MATLAB,
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 58:111 Numerical Calculations Department of Mechanical and Industrial Engineering.
CSE123 Lecture 5 Arrays and Array Operations. Definitions Scalars: Variables that represent single numbers. Note that complex numbers are also scalars,
How to Use MATLAB A Brief Introduction. 2 What can MATLAB do? Matrix Operations Symbolic Computations Simulations Programming 2D/3D Visualization.
1 Lab of COMP 406 Teaching Assistant: Pei-Yuan Zhou Contact: Lab 1: 12 Sep., 2014 Introduction of Matlab (I)
MEGN 536 – Computational Biomechanics MATLAB: Getting Started Prof. Anthony J. Petrella Computational Biomechanics Group.
ECE 1304 Introduction to Electrical and Computer Engineering Section 1.1 Introduction to MATLAB.
A Brief Introduction to Matlab Laila Guessous Dept. of Mechanical Engineering Oakland University.
MATLAB Tutorial EE 327 Signals and Systems 1. What is MATLAB? MATLAB – Matrix Laboratory The premier number-crunching software Extremely useful for signal.
Gulsah Tumuklu Ozyer MATLAB IMAGE PROCESSING TOOLBOX.
What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation tools. Others include Maple Mathematica MathCad.
Matlab Programming for Engineers Dr. Bashir NOURI Introduction to Matlab Matlab Basics Branching Statements Loops User Defined Functions Additional Data.
CS112 Scientific Computation Department of Computer Science Wellesley College Numb3rs Number and image types.
Getting Started with MATLAB CS534 TA: Matt McDaniel Sep 17 th, 2012 Slides by Chunhui Zhu – Fall 2011 Thanks to the help from Tuo.
Introduction MATLAB stands for MATrix LABoratory.  Basics  Matrix Manipulations  MATLAB Programming  Graphics  Image types  Image Processing  Useful.
ES 240: Scientific and Engineering Computation. Chapter 2 Chapter 2: MATLAB Fundamentals Uchechukwu Ofoegbu Temple University.
Digital Image Processing Lecture4: Fundamentals. Digital Image Representation An image can be defined as a two- dimensional function, f(x,y), where x.
Chapter 1 – Matlab Overview EGR1302. Desktop Command window Current Directory window Command History window Tabs to toggle between Current Directory &
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 18P. 1Winter Quarter Introduction to MATLAB Lecture 18.
Working with Arrays in MATLAB
INTRODUCTION TO MATLAB MATLAB is a software package for computation in engineering, science, and applied mathemat-ics. It offers a powerful programming.
Part 1 Chapter 2 MATLAB Fundamentals PowerPoints organized by Dr. Michael R. Gustafson II, Duke University and Prof. Steve Chapra, Tufts University All.
Lecture 20: Choosing the Right Tool for the Job. What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation.
Introduction to Matlab Electromagnetic Theory LAB by Engr. Mian Shahzad Iqbal.
Outline Introduction to MATLAB Image Processing with MATLAB
INTRODUCTION TO MATLAB DAVID COOPER SUMMER Course Layout SundayMondayTuesdayWednesdayThursdayFridaySaturday 67 Intro 89 Scripts 1011 Work
INTRODUCTION TO MATLAB Dr. Hugh Blanton ENTC 4347.
Digital Image Processing Introduction to MATLAB. Background on MATLAB (Definition) MATLAB is a high-performance language for technical computing. The.
Introduction to Engineering MATLAB – 4 Arrays Agenda Creating arrays of numbers  Vectors: 1-D Arrays  Arrays: 2-D Arrays Array Addressing Strings & String.
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)
MA/CS375 Fall MA/CS 375 Fall 2002 Lecture 5.
Lecture 12: M/O/F/ for Engineering Applications B Burlingame 27 April 2016.
การใช้งานโปรแกรม MATLAB ดร. อำนาจ ขาวเน. BASIC ELEMENTS OF MATLAB MATLAB Desktop MATLAB Editor Help System MATLAB (MATrix LABoratory)
An Introduction to Programming in Matlab Emily Blumenthal
Intro To MATLAB CS Fall 2013 Zach Welch. Overview ●Basics ●MATLAB data structures ●Operations ●Useful functions ●Image Processing and other useful.
Computer Application in Engineering Design
ECE 1304 Introduction to Electrical and Computer Engineering
Images In Matlab.
MATLAB DENC 2533 ECADD LAB 9.
Introduction To MATLAB
Lecture 2 Introduction to MATLAB
Communication and Coding Theory Lab(CS491)
How to Use MATLAB A Brief Introduction.
Fundamentals of Image Processing Digital Image Representation
Introduction to Image Processing with MATLAB
Presentation transcript:

Introduction to MATLAB Iran University of Science and Technology, Computer Engineering Department, Introduction to MATLAB Ehsan Adeli M. (eadeli@iust.ac.ir)

Outline Introduction MATLAB Environment Getting Help Vectors, Matrices, and Linear Algebra Plotting User Defined Functions Image Manipulation and Processing Audio Processing Filters and Operations Multimedia Systems (eadeli@iust.ac.ir)

Introduction MATLAB Stands for MATrix LABoratory. The MATLAB environment allows the user to: manage variables import and export data perform calculations generate plots develop and manage files for use with MATLAB. A script can be made with a list of MATLAB commands like other programming language. Multimedia Systems (eadeli@iust.ac.ir)

Environment Multimedia Systems (eadeli@iust.ac.ir)

Getting Help Type one of following commands in the command window: help – lists all the help topic help topic – provides help for the specified topic help command – provides help for the specified command help help – provides information on use of the help command helpwin – opens a separate help window for navigation lookfor keyword – Search all M-files for keyword Or simply press ‘F1’ and use the graphical help window. Multimedia Systems (eadeli@iust.ac.ir)

Variables Variable names: when a semi-colon Must start with a letter May contain only letters, digits, and the underscore “_” Matlab is case sensitive, i.e. one & OnE are different variables. Matlab only recognizes the first 31 characters in a variable name. when a semi-colon >> tutorial = 1234; >> tutorial = 1234 ”;” is placed at the end of each command, the result is not displayed. Multimedia Systems (eadeli@iust.ac.ir)

Variables (Cont’d) Special variables: Commands involving variables: ans : default variable name for the result pi: π = 3.1415926………… eps: ∈ = 2.2204e-016, smallest amount by which 2 numbers can differ. Inf or inf : ∞, infinity NaN or nan: not-a-number Commands involving variables: who: lists the names of defined variables whos: lists the names and sizes of defined variables clear: clears all variables, reset the default values of special variables. clear name: clears the variable name clc: clears the command window clf: clears the current figure and the graph window. Multimedia Systems

Vectors >> x = [ 0 0.25*pi 0.5*pi 0.75*pi pi ] 0 0.7854 1.5708 2.3562 3.1416 >> y = [ 0; 0 25*pi; 0 5*pi; 0 75*pi; ] y = 0.7854 1.5708 y 2.3562 3.1416 Multimedia Systems (eadeli@iust.ac.ir)

Vectors (Cont’d) Vector Addressing – A vector element is addressed in MATLAB with an integer index enclosed in parentheses. >> x(3) The colon notation may be used to address a block of elements (start : increment : end) start is the starting index, increment is the amount to add to each successive index, and end is the ending index. A shortened format (start : end) may be used if increment is 1. >> x(1:3) ans = 0 0.7854 1.5708 NOTE: MATLAB index starts at 1. Multimedia Systems (eadeli@iust.ac.ir)

Vectors (Cont’d) Multimedia Systems (eadeli@iust.ac.ir)

Array Operations Scalar-Array Mathematics: Element-by-Element Array-Array Mathematics: Multimedia Systems (eadeli@iust.ac.ir)

Matrices A Matrix array is two-dimensional, having both multiple rows and multiple columns, similar to vector arrays: It begins with [, and end with ] spaces or commas are used to separate elements in a row semicolon or enter is used to separate rows. Matrix Addressing: matrixname(row, column) colon may be used in place of a row or column reference to select the entire row or column. Multimedia Systems (eadeli@iust.ac.ir)

Matrices (Cont’d) Multimedia Systems (eadeli@iust.ac.ir)

Matrices (Cont’d) Multimedia Systems (eadeli@iust.ac.ir)

Example, Linear Equations Multimedia Systems (eadeli@iust.ac.ir)

Plotting Plotting Curves: Multiple Curves: Multiple Figures: Subplots: plot (x,y) – generates a linear plot of the values of x (horizontal axis) and y (vertical axis). semilogx (x,y) – generate a plot of the values of x and y using a logarithmic scale for x and a linear scale for y semilogy (x,y) – generate a plot of the values of x and y using a linear scale for x and a logarithmic scale for y. loglog(x,y) – generate a plot of the values of x and y using logarithmic scales for both x and y Multiple Curves: plot (x, y, w, z) – multiple curves can be plotted on the same graph by using multiple arguments in a plot command. The variables x, y, w, and z are vectors. Two curves will be plotted: y vs. x, and z vs. w. legend (‘string1’, ‘string2’,…) – used to distinguish between plots on the same graph Multiple Figures: figure (n) – used in creation of multiple plot windows. place this command before the plot() command, and the corresponding figure will be labeled as “Figure n” close – closes the figure n window. close all – closes all the figure windows. Subplots: subplot (m, n, p) – m by n grid of windows, with p specifying the current plot as the pth window Multimedia Systems (eadeli@iust.ac.ir)

Plotting (Cont’d) Multimedia Systems (eadeli@iust.ac.ir)

Flow Control Multimedia Systems (eadeli@iust.ac.ir)

Loops break – is used to terminate the execution of the loop. Multimedia Systems (eadeli@iust.ac.ir)

M-Files A M-file is a group of MATLAB commands. MATLAB can open and execute the commands exactly as if they were entered at the MATLAB command window. To run the M-files, just type the file name in the command window. (make sure the current working directory is set correctly) Multimedia Systems (eadeli@iust.ac.ir)

User Defined Functions Add the following command in the beginning of your m- file: function [output variables] = function_name (input variables); Note that the file name should be the same as the function name. Multimedia Systems (eadeli@iust.ac.ir)

Images in MATLAB 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) MATLAB can also load raw-data or 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 • Binary images : {0,1} • Intensity images : [0,1] or uint8, double etc. • RGB images : m-by-n-by-3 • Indexed images : m-by-3 color map • Multidimensional images m-by-n-by-p (p is the number of layers)

Image import and export Read and write images in Matlab >> I=imread('cells.jpg'); >> imshow(I) >> size(I) ans = 479 600 3 (RGB image) >> Igrey=rgb2gray(I); >> imshow(Igrey) >> imwrite(lgrey, 'cell_gray.tif', 'tiff') Alternatives to imshow >>imagesc(I) >>imtool(I) >>image(I)

Images and Matrices How to build a matrix (or image)? 4 5 6 7 8 9 >> B = zeros(3,3) B = 0 0 0 0 0 0 >> C = ones(3,3) C = 1 1 1 1 1 1 >>imshow(A) (imshow(A,[]) to get automatic pixel range)

Image format conversion Convert between intensity/indexed/RGB to binary format: dither() Convert between intensity format to indexed format: gray2ind() Convert between indexed format to intensity format: ind2gray() Convert between indexed format to RGB format: ind2rgb() Convert a regular matrix to intensity format by scaling: mat2gray() Convert between RGB format to intensity format: rgb2gray() Convert between RGB format to indexed format: rgb2ind() Multimedia Systems (eadeli@iust.ac.ir)

Colormaps I = imread (‘lena.bmp’); imshow (I); colormap (cool); Autumn, bone, colorcube, cool, copper, flag, gray, hot, hsv, jet, pink, prism, spring, summer, white, winter Multimedia Systems (eadeli@iust.ac.ir)

Video mov = aviread(filename) mov = aviread(filename, index) fileinfo = aviinfo(filename) Multimedia Systems (eadeli@iust.ac.ir)

Digital Audio Multimedia Systems (eadeli@iust.ac.ir)

Audio [road,fs]=wavread('road.wav'); The array road now contains the stereo sound data and fs is the sampling frequency.  This data is sampled at the same rate as that on a music CD (fs=44,100 samples/second). The left and right channel signals are the two columns of the road array:  left=road(:,1); right=road(:,2); Multimedia Systems (eadeli@iust.ac.ir)

time=(1/44100)*length(left); t=linspace(0,time,length(left)); plot(t,left) xlabel('time (sec)'); ylabel('relative signal strength') soundsc(left,fs)       % plays left channel as mono  soundsc(right,fs)    % plays right channel mono (sound nearly the same)  soundsc(road,fs)     % plays stereo (ahhh…) Multimedia Systems (eadeli@iust.ac.ir)