Introduction to MATLAB

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
Introduction to MATLAB ES 156 Signals and Systems 2008 Harvard SEAS.
Introduction to MATLAB ES 156 Signals and Systems 2007 Harvard SEAS Prepared by Jiajun Gu.
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.
259 Lecture 15 Introduction to MATLAB. 2 What is MATLAB?  MATLAB, which stands for “MATrix LABoratory” is a high- performance language for technical.
Chapter 10 Review: Matrix Algebra
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.
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
Array Addition  Two arrays can be added if and only if both arrays have exactly the same dimensions.  Assuming the dimension requirement is satisfied,
MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is protected by Copyright.
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.
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.
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.
Introduction to Matlab  Matlab is a software package for technical computation.  Matlab allows you to solve many numerical problems including - arrays.
Introduction to MATLAB 1.Basic functions 2.Vectors, matrices, and arithmetic 3.Flow Constructs (Loops, If, etc) 4.Create M-files 5.Plotting.
MT411 Robotic Engineering Asian Institution of Technology (AIT) Chapter 1 Introduction to Matrix Narong Aphiratsakun, D.Eng.
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.
Finishing up Chapter 5. Will this code enter the if statement? G=[30,55,10] if G
MATLAB (Matrix Algebra laboratory), distributed by The MathWorks, is a technical computing environment for high performance numeric computation and.
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
Linear Algebra Review.
Introduction to MATLAB
Linear Algebraic Equations and Matrices
Linear Algebra Lecture 2.
응용 전산 및 실습 MATLAB – Chapter 3 행렬연산
Signals in Matlab Matlab as a name stands for Matrix Laboratory.
Lecture 25.
Linear Algebraic Equations and Matrices
Ch3 Graphics Overview of Plotting Editing Plots
TexPoint fonts used in EMF.
EGR 106 – Week 4 – Math on Arrays
MATLAB DENC 2533 ECADD LAB 9.
Introduction to Matlab
Introduction To MATLAB
EEE 244 Numerical Methods In Electrical Engineering
Digital Image Processing using MATLAB
Introduction to MATLAB Lecture 02
Lecture 2 Introduction to MATLAB
Digital Image Processing
Communication and Coding Theory Lab(CS491)
Introduction to MATLAB
INTRODUCTION TO MATLAB
Demo of Basic Matlab Features
Announcements P3 due today
How to Use MATLAB A Brief Introduction.
Presentation transcript:

Introduction to MATLAB

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

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 Workspace History Command

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 = 16 3 5 10

Matrices & Vectors - II Order of Matrix - Vectors - special case 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 >> A = [16 3; 5 10] A = 16 3 5 10 >> B = [3 4 5 6 7 8] B = 3 4 5 6 7 8 Matrix: >> A=[1 2; 3 4]; >> A' ans = 1 3 2 4 Vector : >> a=[1 2 3]; >> a' 1 2 3

Creating Vectors Create vector with equally spaced intervals >> x=0:0.5:pi x = 0 0.5000 1.0000 1.5000 2.0000 2.5000 3.0000 Create vector with n equally spaced intervals >> x=linspace(0, pi, 7) x = 0 0.5236 1.0472 1.5708 2.0944 2.6180 3.1416 Equal spaced intervals in logarithm space >> x=logspace(1,2,7) x = 10.0000 14.6780 21.5443 … 68.1292 100.0000 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 But: >> A.*B 5 12 21 32 >> A=[1 2;3 4]; >> B=[5 6;7 8]; >> A*B 19 22 43 50

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) = 0.6068 0.2311 ] A(1,2:3)=[0.6068 0.4231] n A = 0.9501 0.6068 0.4231 0.2311 0.4860 0.2774 m 1:m

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

Graphics - 2D Plots For example: Gives: 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'); >> title('Sine');

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 >> 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')

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.

Practice Problems 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