Introduction to MATLAB ES 156 Signals and Systems 2007 Harvard SEAS Prepared by Jiajun Gu.

Slides:



Advertisements
Similar presentations
Tutorial on Matlab and OpenCV Rui Ma TA of CMPT 414 May 14, 2013 Office hours: Fridays 11:00-12:00, CSIL TA Office 1 (ASB 9838)
Advertisements

Introduction to MATLAB The language of Technical Computing.
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.
MATLAB - Basics Centro de Informática Universidade Federal de Pernambuco Aprendizagem de Máquina – IN1102 Arley Ristar –
Slide deck by Dr. Greg Reese Miami University MATLAB An Introduction With Applications, 5 th Edition Dr. Amos Gilat The Ohio State University Chapter 3.
Introduction to MATLAB Simon O’Keefe Non-Standard Computation Group
EGR 106 – Week 4 – Math on Arrays
Introduction to MATLAB ES 156 Signals and Systems 2008 Harvard SEAS.
Modified Gary Larson Far Side cartoon
Matlab intro The Environment
EPSII 59:006 Spring Outline Managing Your Session File Usage  Saving Workspace  Loading Data Files  Creating M-files More on Matrices Review.
MATLAB Fundamentals.
259 Lecture 15 Introduction to MATLAB. 2 What is MATLAB?  MATLAB, which stands for “MATrix LABoratory” is a high- performance language for technical.
MATLAB Basics With a brief review of linear algebra by Lanyi Xu modified by D.G.E. Robertson.
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 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
ELG 3120 Signal and System Analysis 1 Introduction to MATLAB TAs Wei Zhang Ozgur Ekici (Section A)(Section B) ELG 3120 Lab Tutorial 1.
Array Addition  Two arrays can be added if and only if both arrays have exactly the same dimensions.  Assuming the dimension requirement is satisfied,
1 Lab of COMP 406 Teaching Assistant: Pei-Yuan Zhou Contact: Lab 1: 12 Sep., 2014 Introduction of Matlab (I)
Introduction to MATLAB CBE 502 Mathematical Methods of Engineering Analysis.
Learner’s Guide to MATLAB® Chapter 2 : Working with Arrays.
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.
INTRODUCTION TO MATLAB LAB# 01
CMPS 1371 Introduction to Computing for Engineers MATRICES.
Basics of MATLAB By DR. Wafaa Shabana
CDA6530: Performance Models of Computers and Networks Chapter 4: Using Matlab for Performance Analysis and Simulation TexPoint fonts used in EMF. Read.
MATLAB 程式設計 Learning Linear Algebra 方煒 台大生機系. MATLAB 程式設計 Vector Products, Dot and Cross a=[1,2,3];b=[3,2,1]; C=a*b D=a.*b E=dot(a,b) F=cross(a,b)
Matlab 14.html Cost: $100 Available in labs on Windows and Unix machines.
ES 240: Scientific and Engineering Computation. Chapter 2 Chapter 2: MATLAB Fundamentals Uchechukwu Ofoegbu Temple University.
Introduction to MATLAB Session 1 Simopekka Vänskä, THL 2010.
OUTLINE Overview Numbers, variables and similar in Matlab
Barbara/Pratik/Yu. Outline Matlab desktop M-files Variables Arrays Plots.
Master in Optical Fiber Communications and Photonic Technologies Foundations of Digital Transmission - Fall quarter Introduction to Matlab.
INTRODUCTION TO MATLAB MATLAB is a software package for computation in engineering, science, and applied mathemat-ics. It offers a powerful programming.
Matlab Screen  Command Window  type commands  Current Directory  View folders and m-files  Workspace  View program variables  Double click on a.
A string is an array of characters Strings have many uses in MATLAB Display text output Specify formatting for plots Input arguments for some functions.
Sept. 26, 2005 Lecture 6 - By Paul Lin 1 CPET 190 Lecture 6 Problem Solving with MATLAB
Introduction to Matlab  Matlab is a software package for technical computation.  Matlab allows you to solve many numerical problems including - arrays.
INTRODUCTION TO MATLAB Dr. Hugh Blanton ENTC 4347.
Introduction to MATLAB 1.Basic functions 2.Vectors, matrices, and arithmetic 3.Flow Constructs (Loops, If, etc) 4.Create M-files 5.Plotting.
1 Lecture 5 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.
ECE 351 M ATLAB I NTRODUCTION ( BY T EACHING A SSISTANTS )
1 Lecture 3 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.
Spring 2016 Statics - TAM 210 & TAM 211 Discussion 1 - Intro to Matlab 1.
MATLAB Lecture 1 염익준. Introduction MATLAB (MATrix LABoratory) a special purpose computer program optimized to perform engineering and scientific calculations.
1 Faculty Name Prof. A. A. Saati. 2 MATLAB Fundamentals 3 1.Reading home works ( Applied Numerical Methods )  CHAPTER 2: MATLAB Fundamentals (p.24)
Finishing up Chapter 5. Will this code enter the if statement? G=[30,55,10] if G
CS100A, Fall 1998, Lecture 201 CS100A, Fall 1998 Lecture 20, Tuesday Nov 10 More Matlab Concepts: plotting (cont.) 2-D arrays Control structures: while,
MATLAB (Matrix Algebra laboratory), distributed by The MathWorks, is a technical computing environment for high performance numeric computation and.
NoViC, Dept. of Mechanical Eng Acoustics Lab., NoViC 1. Download Matlab 2.
Outline What is MATLAB MATLAB desktop Variables, Vectors and Matrices Matrix operations Array operations Built-in functions: Scalar, Vector, Matrix Data.
MATLAB: How do you work with data to solve problems?
ECE 1304 Introduction to Electrical and Computer Engineering
Introduction to MATLAB
Introduction to MATLAB
응용 전산 및 실습 MATLAB – Chapter 3 행렬연산
TexPoint fonts used in EMF.
EGR 106 – Week 4 – Math on Arrays
MATLAB DENC 2533 ECADD LAB 9.
Introduction to Matlab
Digital Image Processing using MATLAB
Lecture 2 Introduction to MATLAB
How to Use MATLAB A Brief Introduction.
Presentation transcript:

Introduction to MATLAB ES 156 Signals and Systems 2007 Harvard SEAS Prepared by Jiajun Gu

Outline Introduction and where to get MATLAB Data structure: matrices, vectors and operations Basic line plots File I/O

Where to get MATLAB FAS computing: –Download from –You must be on FAS network to use MATLAB HSEAS IT –Maxwell Dworkin Rooms G107-G111 Mathworks: –Student version is affordable and complete.

What is MATLAB High level language for technical computing Stands for MATrix LABoratory Everything is a matrix - easy to do linear algebra

The MATLAB System Development Environment Mathematical Function Library MATLAB language Application Programming Language (not discussed today)

MATLAB Desktop Menu and toolbar Command History Workspace

Matrices & Vectors All (almost) entities in MATLAB are matrices Easy to define: Use ‘,’ or ‘ ’ to separate row elements -- use ‘;’ to separate rows >> A = [16 3; 5 10] A =

Matrices & Vectors - II Order of Matrix - –m=no. of rows, n=no. of columns Vectors - special case –n = 1 column vector –m = 1 row vector

Creating Vectors and Matrices Define Transpose Vector : >> a=[1 2 3]; >> a' Matrix: >> A=[1 2; 3 4]; >> A' ans = >> A = [16 3; 5 10] A = >> B = [ ] B =

Creating Vectors Create vector with equally spaced intervals >> x=0:0.5:pi x = Create vector with n equally spaced intervals >> x=linspace(0, pi, 7) x = Equal spaced intervals in logarithm space >> x=logspace(1,2,7) x = … Note: MATLAB uses pi to represent, uses i or j to represent imaginary unit

Creating Matrices zeros(m, n): matrix with all zeros ones(m, n): matrix with all ones. eye(m, n): the identity matrix rand(m, n): uniformly distributed random randn(m, n): normally distributed random magic(m): square matrix whose elements have the same sum, along the row, column and diagonal. pascal(m) : Pascal matrix.

Matrix operations ^: exponentiation *: multiplication /: division \: left division. The operation A\B is effectively the same as INV(A)*B, although left division is calculated differently and is much quicker. +: addition -: subtraction

Array Operations Evaluated element by element.' : array transpose (non-conjugated transpose).^ : array power.* : array multiplication./ : array division Very different from Matrix operations >> A=[1 2;3 4]; >> B=[5 6;7 8]; >> A*B But: >> A.*B

Some Built-in functions mean(A): mean value of a vector max(A), min (A): maximum and minimum. sum(A): summation. sort(A): sorted vector median(A): median value std(A): standard deviation. det(A) : determinant of a square matrix dot(a,b): dot product of two vectors Cross(a,b): cross product of two vectors Inv(A): Inverse of a matrix A

Indexing Matrices Given the matrix: Then: A(1,2) = A(3) = A(:,1) = [ ] A(1,2:3)=[ ] A = m n 1:m

>> A=1:3 A= >> A(4:6)=5:2:9 A= >> B=1:2 B= 1 2 >> B(5)=7; B= >> C=[1 2; 3 4] C= >> C(3,:)=[5 6]; C= >> D=linspace(4,12,3); >> E=[C D’] E= Adding Elements to a Vector or a Matrix

Graphics - 2D Plots plot(xdata, ydata, ‘marker_style’); For example: Gives: >> x=-5:0.1:5; >> sqr=x.^2; >> pl1=plot(x, sqr, 'r:s');

Graphics - Overlay Plots Use hold on for overlaying graphs So the following:Gives: >> hold on; >> cub=x.^3; >> pl2=plot(x, cub,‘b-o');

Graphics - Annotation Use title, xlabel, ylabel and legend for annotation >> title('Demo plot'); >> xlabel('X Axis'); >> ylabel('Y Axis'); >> legend([pl1, pl2], 'x^2', 'x^3');

Graphics - Annotation

Graphics-Stem() stem() is to plot discrete sequence data The usage of stem() is very similar to plot() >> n=-10:10; >> f=stem(n,cos(n*pi/4)) >> title('cos(n\pi/4)') >> xlabel('n')

subplots Use subplots to divide a plotting window into several panes. >> x=0:0.1:10; >> f=figure; >> f1=subplot(1,2,1); >> plot(x,cos(x),'r'); >> grid on; >> title('Cosine') >> f2=subplot(1,2,2); >> plot(x,sin(x),'d'); >> grid on; >> title('Sine');

>> f=figure; >> x=-5:0.1:5; >> h=plot(x,cos(2*x+pi/3)); >> title('Figure 1'); >> xlabel('x'); >> saveas(h,'figure1.fig') >> saveas(h,'figure1.eps') Save plots Use saveas(h,'filename.ext') to save a figure to a file. Useful extension types: bmp: Windows bitmap emf: Enhanced metafile eps: EPS Level 1 fig: MATLAB figure jpg: JPEG image m: MATLAB M-file tif: TIFF image, compressed

Workspace Matlab remembers old commands And variables as well Each Function maintains its own scope The keyword clear removes all variables from workspace The keyword who lists the variables

File I/O Matlab has a native file format to save and load workspaces. Use keywords load and save. In addition MATLAB knows a large number of popular formats. Type “help fileformats” for a listing. In addition MATLAB supports ‘C’ style low level file I/O. Type “ help fprintf ” for more information.

Plot the following signals in linear scale Plot the following signals, use log scale for y-axis Plot the real part and imaginary part of the following signal For the signal in previous question, plot its phase and magnitude Practice Problems