CS231A Matlab Tutorial Philip Lee Winter 2015. Overview  Goals › Introduction to Matlab › Matlab Snippets › Basic image manipulations › Helpful Matlab.

Slides:



Advertisements
Similar presentations
Introduction to Matlab
Advertisements

MATLAB – A Computational Methods By Rohit Khokher Department of Computer Science, Sharda University, Greater Noida, India MATLAB – A Computational Methods.
Introduction to MATLAB The language of Technical Computing.
Introduction to M ATLAB Programming Ian Brooks Institute for Climate & Atmospheric Science School of Earth & Environment
Introduction to Matlab
Introduction to Matlab Workshop Matthew Johnson, Economics October 17, /13/20151.
Introduction to MATLAB for Biomedical Engineering BME 1008 Introduction to Biomedical Engineering FIU, Spring 2015 Lesson 2: Element-wise vs. matrix operations.
MATLAB – What is it? Computing environment / programming language Tool for manipulating matrices Many applications, you just need to get some numbers in.
MATLAB for Image Processing April 10 th, Outline Introduction to MATLAB –Basics & Examples Image Processing with MATLAB –Basics & Examples.
Lecture 5 Review Programming Program Structures Comparison Repetition: looping or iteration Conditional execution: branching Bubble Sort.
Introduction to Matlab By: Dr. Maher O. EL-Ghossain.
Introduction to MATLAB Northeastern University: College of Computer and Information Science Co-op Preparation University (CPU) 10/22/2003.
EGR 106 – Week 2 – Arrays Definition, size, and terminology Construction methods Addressing and sub-arrays Some useful functions for arrays Character arrays.
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 Tutorial for CS4MN3/SE3X03 Wen Yu McMaster University.
1 Introduction to MatLab MatLab stands for Matrix Laboratory. As the name suggests most of the programming operations have as input or output a matrix.
Dr. Jie Zou PHY Welcome to PHY 3320 Computational Methods in Physics and Engineering.
Introduction to MATLAB MECH 300H Spring Starting of MATLAB.
Introduction to Matlab Jianguo Wang CSSCR September 2009.
What is MATLAB ? MATrix LABratory –Originally, it was a front-end to FORTRAN matrix routines developed in the U. of New Mexico and Stanford –Today.
Chapter 5 Review: Plotting Introduction to MATLAB 7 Engineering 161.
Matlab tutorial course Lesson 2: Arrays and data types
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.
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
Matlab tutorial course Lesson 5: Loading and writing data, producing visual output
ELG 3120 Signal and System Analysis 1 Introduction to MATLAB TAs Wei Zhang Ozgur Ekici (Section A)(Section B) ELG 3120 Lab Tutorial 1.
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.
Computational Methods of Scientific Programming Lecturers Thomas A Herring, Room A, Chris Hill, Room ,
COMP 116: Introduction to Scientific Programming Lecture 6: Scripts and publishing, Creating matrices.
INTRODUCTION TO MATLAB LAB# 01
Matlab The language of Technical computing Mr. D. Suresh Assistant Professor, Dept. of CSE, PSNA CET, Dindigul.
Introduction MATLAB stands for MATrix LABoratory.  Basics  Matrix Manipulations  MATLAB Programming  Graphics  Image types  Image Processing  Useful.
Introduction to Matlab. Outline:  What is Matlab? Matlab Screen Variables, array, matrix, indexing Operators (Arithmetic, relational, logical ) Display.
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 &
Matlab Screen  Command Window  type commands  Current Directory  View folders and m-files  Workspace  View program variables  Double click on a.
Files: By the end of this class you should be able to: Prepare for EXAM 1. create an ASCII file describe the nature of an ASCII text Use and describe string.
Introduction to Matlab
Matlab tutorial course Exercises 5: Loading and writing images
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 MATLAB 1.Basic functions 2.Vectors, matrices, and arithmetic 3.Flow Constructs (Loops, If, etc) 4.Create M-files 5.Plotting.
CSE 455 : Computer Vision MATLAB 101 Getting Started with MATLAB.
Image Representation Last update st March Heejune Ahn, SeoulTech.
Math 252: Math Modeling Eli Goldwyn Introduction to MATLAB.
Intro to Matlab Yipei Wang & Qihui Li {yipeiw,
CS100A, Fall 1998, Lecture 201 CS100A, Fall 1998 Lecture 20, Tuesday Nov 10 More Matlab Concepts: plotting (cont.) 2-D arrays Control structures: while,
Introduction to MATLAB CS 534 Fall What you'll be learning today ●MATLAB basics (debugging, IDE) ●Operators ●Matrix indexing ●Image I/O ●Image display,
An Introduction to Programming in Matlab Emily Blumenthal
MAE 421 Matlab review Prof. Mark Glauser Created by: David Marr.
Basics of MATLAB 2- Programming in MATLAB By DR. Wafaa Shabana
L – Modeling and Simulating Social Systems with MATLAB
Lecture: MATLAB Chapter 1 Introduction
Introduction to MATLAB
Outline Matlab tutorial How to start and exit Matlab Matlab basics.
MATLAB DENC 2533 ECADD LAB 9.
Matlab Workshop 9/22/2018.
Digital Image Processing using MATLAB
Use of Mathematics using Technology (Maltlab)
CSE107 Matlab Introduction
CS 175 Project in AI Discussion -- matlab
CSE 307 Basics of Image Processing
Introduction to MATLAB
MATLAB stands for MATrix LABoratory.
Presentation transcript:

CS231A Matlab Tutorial Philip Lee Winter 2015

Overview  Goals › Introduction to Matlab › Matlab Snippets › Basic image manipulations › Helpful Matlab tips and tricks

What is Matlab? › MAtrix LABratory › Scientific Tool › Good for: Numerical analysis Prototyping Scientific computations › Not good for Symbolic analysis Large Systems Computational efficiency

How to Get Matlab › Buy through Stanford arelic/matlabhttps://itservices.stanford.edu/service/softw arelic/matlab › Use the corn cluster SSH into corn and use the following commands –module load matlab –matlab &

Matlab Screenshot Workspace Files in directory “.m” files Publish

Small Matlab Snippets

Publishing Scripts Publish your scripts! This makes it readable and inlines all of your plots/images

Small Matlab Snippets – Matrices / Vector Definitions All variables in Matlab are matrices Vectors are special cases of matrices Case sensitive Int, float, double, char, logical data types Variations of these, i.e. uint8 Semicolons suppress outputs Surround chars with single quotes (e.g. ‘c’) Use spaces or colons to delineate values horizontally Use semicolons to delineate values vertically

Small Matlab Snippets – Sequences You can make row vectors of sequences very easily Forward Backward Skipping

Small Matlab Snippets – Matrix Manipulations Tranpose Use single quote Indexing Starts at 1! Can specify individual or group of values Can use with multi- dimensional arrays Can use end to denote end index

Small Matlab Snippets – Vector Indexing Examples

Small Matlab Snippets – Matrix Indexing Examples

Matrix Operations vs Element-wise Operations Default operators are Matrix operations + - * / ^ Matrix-Matrix OR Matrix- vector operations There are analogous element-wise operators + -.*./.^ Scalar-Scalar operations

Matrix Operations vs Element-wise Operations Examples

Control Flow Comparison operators >, >=, <, <=, ==, != If-elseif-else statements While statements For loops Can use logical values

Functions Function example ones(M,N) or ones([M,N]) is an M-by-N matrix of ones. Function definitions Use a separate file Generally not needed for homework assignments Help command is your friend! The following two syntaxes are equivalent Function(‘arg’) Function arg

Useful Functions Ones / zeros Create a matrix of ones or zeros Size Dimensions of the matrix Diag (overloaded) Diagonal elements of a matrix create a diagonal matrix from a vector Rand / randi / randn Random generators Max / min / sum / mean / median Sort Svd, eig, Much more…

Plotting Figures Hold individual image / plot Plots will overwrite each other unless you specify otherwise Use the ‘hold’ command to lay plots on top of each other Use the ‘figure’ command to specify which figure to use or if you should open a new figure Title Use ‘title’ command Label axes xlabel ylabel

Plotting (cont.) Various displaying functions Plot Scatter Stem Imshow Shows an image (see next section)

Plotting Examples Can plot a vector as a sequence

Plotting Examples (cont.) Can plot two vector as ordered pairs

Images Representation Data type Float / Double –0 is black –1 is white (or saturated) Int –0 is black –255 is white (or saturated)  Can manipulate an image like any other matrix (after it’s read in) Format RGB –M x N x 3 –Can think of as R,G, and B images laid on top of each other –Can be floats or ints Grayscale –M x N –Can be floats or ints Binary –M x N –Logical values

Image functions Imread(‘filename’) Reads in image as an RGB image Saves image as a matrix representation (m x n x 3) Imshow(matrix) Displays matrix as if it were an image Interprets scale (0 to 1 or 0 to 255) based on data type Interprets RGB vs Grayscale based on dimensionality Can convert between image types Rgb2gray, gray2rgb Cast data May need to scale

Image functions Imread(‘filename’) Reads in image as an RGB image Saves image as a matrix representation (m x n x 3) Imshow(matrix) Displays matrix as if it were an image Interprets scale (0 to 1 or 0 to 255) based on data type Interprets RGB vs Grayscale based on dimensionality Can convert between image types Rgb2gray, gray2rgb Cast data May need to scale

Tips and Tricks Use the publish command to submit your work! We will expect work to be published when you submit to Scoryst Make sure your dimensions are right. Element-wise vs matrix operators are the most common mistake by beginners Use matrix operations instead of for loops. That’s what Matlab is for! Use comments Functions when necessary May be needed for your project

More Text

Questions? Please feel free to ask questions in Class Discussion sections Prof. Office Hours TA Office hours Piazza › RIGHT NOW