An Introduction to Programming in Matlab Emily Blumenthal

Slides:



Advertisements
Similar presentations
MATLAB – A Computational Methods By Rohit Khokher Department of Computer Science, Sharda University, Greater Noida, India MATLAB – A Computational Methods.
Advertisements

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
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.
EGR 106 – Week 2 – Arrays Definition, size, and terminology Construction methods Addressing and sub-arrays Some useful functions for arrays Character arrays.
Introduction to MATLAB
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.
Lecture 2 MATLAB fundamentals Variables, Naming Rules, Arrays (numbers, scalars, vectors, matrices), Arithmetical Operations, Defining and manipulating.
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.
Introduction to Matlab Jianguo Wang CSSCR September 2009.
Part 1 Chapter 2 MATLAB Fundamentals
MATLAB Fundamentals.
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.
1 MATLAB 基礎. 2 MATLAB  Workspace: environment (address space) where all variables reside  After carrying out a calculation, MATLAB assigns the result.
Lecture 13: M/O/F/ for Engineering Applications - Part 1 BJ Furman 26NOV2012.
MATLAB Lecture One Monday 4 July Matlab Melvyn Sim Department of Decision Sciences NUS Business School
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 Session 1 Prepared By: Dina El Kholy Ahmed Dalal Statistics Course – Biomedical Department -year 3.
Introduction to MATLAB January 18, 2008 Steve Gu Reference: Eta Kappa Nu, UCLA Iota Gamma Chapter, Introduction to MATLAB,
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.
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.
Introduction to Matlab Module #2 Page 1 Introduction to Matlab Module #2 – Arrays Topics 1.Numeric arrays (creation, addressing, sizes) 2.Element-by-Element.
10/24/20151 Chapter 2 Review: MATLAB Environment Introduction to MATLAB 7 Engineering 161.
Lecture 2 - Matlab Introduction CVEN 302 June 5, 2002.
Matlab 14.html Cost: $100 Available in labs on Windows and Unix machines.
Introduction MATLAB stands for MATrix LABoratory.  Basics  Matrix Manipulations  MATLAB Programming  Graphics  Image types  Image Processing  Useful.
Introduction to MATLAB ENGR 1181 MATLAB 1. Opening MATLAB  Students, please open MATLAB now.  CLICK on the shortcut icon → Alternatively, select… start/All.
ES 240: Scientific and Engineering Computation. Chapter 2 Chapter 2: MATLAB Fundamentals Uchechukwu Ofoegbu Temple University.
Working with Arrays in MATLAB
Matlab Screen  Command Window  type commands  Current Directory  View folders and m-files  Workspace  View program variables  Double click on a.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Introduction to MATLAB 7 for Engineers William J. Palm.
>> x = [ ]; y = 2*x y = Arrays x and y are one dimensional arrays called vectors. In MATLAB all variables are arrays. They allow functions.
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.
Array Creation ENGR 1181 MATLAB 2. Civil engineers store seismic data in arrays to analyze plate tectonics as well as fault patterns. These sets of data.
Introduction to Matlab  Matlab is a software package for technical computation.  Matlab allows you to solve many numerical problems including - arrays.
Array Creation ENGR 1187 MATLAB 2. Today’s Topics  Arrays: What are they?  Vectors  Matrices  Creating Arrays.
INTRODUCTION TO MATLAB DAVID COOPER SUMMER Course Layout SundayMondayTuesdayWednesdayThursdayFridaySaturday 67 Intro 89 Scripts 1011 Work
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.
CMPS 1371 Introduction to Computing for Engineers VECTORS.
CSE 455 : Computer Vision MATLAB 101 Getting Started with MATLAB.
NET 222: COMMUNICATIONS AND NETWORKS FUNDAMENTALS ( NET 222: COMMUNICATIONS AND NETWORKS FUNDAMENTALS (PRACTICAL PART) Tutorial 2 : Matlab - Getting Started.
1 Faculty Name Prof. A. A. Saati. 2 MATLAB Fundamentals 3 1.Reading home works ( Applied Numerical Methods )  CHAPTER 2: MATLAB Fundamentals (p.24)
Math 252: Math Modeling Eli Goldwyn Introduction to MATLAB.
Manipulating MATLAB Vector, Matrices 1. Variables and Arrays What are variables? You name the variables (as the programmer) and assign them numerical.
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)
MATLAB (Matrix Algebra laboratory), distributed by The MathWorks, is a technical computing environment for high performance numeric computation and.
1-2 What is the Matlab environment? How can you create vectors ? What does the colon : operator do? How does the use of the built-in linspace function.
ENG College of Engineering Engineering Education Innovation Center 1 Arrays in MATLAB Topics Covered: 1.Creating arrays of numbers vectors matrices.
ECE 1304 Introduction to Electrical and Computer Engineering
Introduction to Matlab
MATLAB DENC 2533 ECADD LAB 9.
Communication and Coding Theory Lab(CS491)
MATLAB stands for MATrix LABoratory.
Presentation transcript:

An Introduction to Programming in Matlab Emily Blumenthal

What is Matlab? MATrix LABoratory o Stores information as N x M x … dimensional matrices Applications include o Matrix manipulation o Digital signal processing o 3D Graphics Toolboxes for specific needs o Statistics Toolbox o Psychtoolbox

Matlab Resources Matlab tutorials: o center/tutorials/mltutorial_launchpad.html# o Matlab lessons from Ione Fine and Geoff Boynton: l o demo help COMMAND doc COMMAND helpdesk

The Matlab Environment List of stored variables Command history Lists commands and answers

Matlab as a Calculator Each result is saved in a separate variable All variables are arrays -- the fundamental data type in Matlab is a matrix; even scalars are saved as 1X1 arrays. Variables come in different sizes e.g. m X n X p X... There are different classes of data types, default numerical data type is a double. The double data type is a floating point number with 16 digits of precision.

Variables in Memory Who: Gives you a list of all of the variables you have in memory Whos: Gives you the name of each variable, how long it is, how much computer memory the list uses, and the type of variable (e.g. a list of characters -- char -- or double. Disp: Displays a particular variable Clear x: deletes a particular variable from memory Clear all: deletes all variables from memory

M-Files and Paths File -> New -> Blank M-File Create a comment o % Set a path: Path, pwd, cd

Saving & Reading Data.mat format o save filename variables o load filename Excel o xlswrite(File, Array, Sheet, Range) o xlsread(File, Sheet, Range) Can also read/write from a text file

Basic Plotting gcf -- get current figure (handle/pointer) gca -- get handle to current axis Change figure properties using the set command o set(gcf, ‘COMMAND’, PROPERTY)

Basic Plotting

More Plotting Error bar plots: errorbar(X,Y,L,U) o Plots the graph of vector X vs. vector Y with error bars specified by vectors L and U Bar Graphs: bar(X,Y) o Plots a bar graph of X and Y. o bar(X,Y,WIDTH) specifies the width of the bars. WIDTH>1 produces overlapping bars Histograms: hist(Y,M) o Groups data Y into M bins

Saving Figures saveas(‘x’, FILENAME, FORMAT) o E.g. saveas(gcf, ‘myhistogram’, ‘jpg’) o Writes current figure to a jpg file, saved in current working directory

3D Plotting mesh(X,Y,Z): plots the colored parametric mesh defined by the matrices X, Y, and Z. The axes are determined by the range of X, Y, and Z surf(X,Y,Z): plots a 3D colored surface defined by matrices X, Y, and Z help('graph3d')

Basic Graphics image(C): displays the current matrix as an image imagesc(C): scale data and display as an image; scaled to use full colormap colormap(MAP): sets the current figure’s color to MAP

Strings and Vectors String: a sequence of letters stored as a variable string1='hello world!'; o Single quotes identify a string Vector: a 1 X n array of numbers vector1=[ ]; o Square brackets identify a vector o linspace and the : operator

Indexing and Subscripting string1=‘hello world!’ string1(2)=e string1(12)=‘?’ >> string1(12)='?' string1 = hello world? vector1=1:10:100 >> vector1(3)=21 >> vector1(3:5)=

Matrices 2 dimensional matrices: o mat1=[ ; ; ] o mat1=[ ] use square brackets to concatenate, enter values sequentially in rows; semicolon (;)marks the start of a new row. Column separator is a comma or a space, row separator is a semicolon or enter o Zeros, ones, rand, magic, eye etc.

Indexing into Matrices Vectors and scalars are initialized the same way as matrices. It is important to note that MATLAB indexes matrices in the following manner: (1,1) (1,2) (1,3) (1,4) (2,1) (2,2) (2,3) (2,4) This means that the first element always has index (1,1), not (0,0).

Matrix Operations size(mat) Transpose using a single quote (‘) Addition and subtraction o Operations with scalars o Operations with vectors of the same size Scalar multiplication and division Matrix multiplication and division

Matrix Operations (from Matlab’s tutorial)