Lecturer: Keyvan Dehmamy

Similar documents
MATLAB Tutorial. Digital Signal Processing. Course Details. Topics. MATLAB Environment. Introduction. Digital Signal Processing (DSP)

Introduction to MATLAB

Introduction to Matlab

Introduction to. The Help System. Variable and Memory Management. Matrices Generation. Interactive Calculations. Vectors and Matrices

Finding, Starting and Using Matlab

A General Introduction to Matlab

ELEC4042 Signal Processing 2 MATLAB Review (prepared by A/Prof Ambikairajah)

Some elements for Matlab programming

Getting started with MATLAB

MATLAB BASICS. < Any system: Enter quit at Matlab prompt < PC/Windows: Close command window < To interrupt execution: Enter Ctrl-c.

Introduction to MATLAB

Laboratory 1 Octave Tutorial

Part #1. A0B17MTB Matlab. Miloslav Čapek Filip Kozák, Viktor Adler, Pavel Valtr

MATLAB Lesson I. Chiara Lelli. October 2, Politecnico di Milano

Chapter 1 Introduction to MATLAB

Stokes Modelling Workshop

MATLAB Fundamentals. Berlin Chen Department of Computer Science & Information Engineering National Taiwan Normal University

Chapter 2. MATLAB Fundamentals

Outline. CSE 1570 Interacting with MATLAB. Outline. Starting MATLAB. MATLAB Windows. MATLAB Desktop Window. Instructor: Aijun An.

A very brief Matlab introduction

Introduction to MATLAB for Numerical Analysis and Mathematical Modeling. Selis Önel, PhD

Introduction to Engineering gii

PowerPoints organized by Dr. Michael R. Gustafson II, Duke University

Inlichtingenblad, matlab- en simulink handleiding en practicumopgaven IWS

Introduction to MATLAB. Computational Probability and Statistics CIS 2033 Section 003

Matlab Workshop I. Niloufer Mackey and Lixin Shen

MATLAB Constants, Variables & Expression. 9/12/2015 By: Nafees Ahmed

Dr Richard Greenaway

A Quick Tutorial on MATLAB. Zeeshan Ali

Constraint-based Metabolic Reconstructions & Analysis H. Scott Hinton. Matlab Tutorial. Lesson: Matlab Tutorial

MATLAB Workshop Dr. M. T. Mustafa Department of Mathematical Sciences. Introductory remarks

Outline. CSE 1570 Interacting with MATLAB. Starting MATLAB. Outline. MATLAB Windows. MATLAB Desktop Window. Instructor: Aijun An.

Introduction to Scientific and Engineering Computing, BIL108E. Karaman

Interactive Computing with Matlab. Gerald W. Recktenwald Department of Mechanical Engineering Portland State University

Prof. Manoochehr Shirzaei. RaTlab.asu.edu

Introduzione a MatLab. Prof. Sebastiano Battiato

A Guide to Using Some Basic MATLAB Functions

A QUICK INTRODUCTION TO MATLAB

Computer Programming in MATLAB

A QUICK INTRODUCTION TO MATLAB. Intro to matlab getting started

Introduction to Matlab. High-Level Computer Vision Summer Semester 2015

Introduction to GNU-Octave

Introduction to MATLAB

An Introduction to MATLAB II

Lecture 1: What is MATLAB?

Programming in Mathematics. Mili I. Shah

UNIVERSITI TEKNIKAL MALAYSIA MELAKA FAKULTI KEJURUTERAAN ELEKTRONIK DAN KEJURUTERAAN KOMPUTER

Matlab Lecture 1 - Introduction to MATLAB. Five Parts of Matlab. Entering Matrices (2) - Method 1:Direct entry. Entering Matrices (1) - Magic Square

2.0 MATLAB Fundamentals

CDA6530: Performance Models of Computers and Networks. Chapter 4: Using Matlab for Performance Analysis and Simulation

CDA6530: Performance Models of Computers and Networks. Chapter 4: Using Matlab for Performance Analysis and Simulation

PART 1 PROGRAMMING WITH MATHLAB

Chapter 1 MATLAB Preliminaries

Why use MATLAB? Mathematcal computations. Used a lot for problem solving. Statistical Analysis (e.g., mean, min) Visualisation (1D-3D)

Fundamentals of MATLAB Usage

Outline. CSE 1570 Interacting with MATLAB. Starting MATLAB. Outline (Cont d) MATLAB Windows. MATLAB Desktop Window. Instructor: Aijun An

CDA5530: Performance Models of Computers and Networks. Chapter 8: Using Matlab for Performance Analysis and Simulation

MATLAB Tutorial EE351M DSP. Created: Thursday Jan 25, 2007 Rayyan Jaber. Modified by: Kitaek Bae. Outline

Introduction to MATLAB LAB 1

AN INTRODUCTION TO MATLAB

INTRODUCTION TO MATLAB, SIMULINK, AND THE COMMUNICATION TOOLBOX

QUICK INTRODUCTION TO MATLAB PART I

ENGR Fall Exam 1

Introduction to MATLAB

MATLAB and Numerical Analysis

MATLAB Programming for Numerical Computation Dr. Niket Kaisare Department Of Chemical Engineering Indian Institute of Technology, Madras

Introduction to MATLAB

Introduction to MATLAB Programming

Matlab Tutorial, CDS

What is MATLAB? It is a high-level programming language. for numerical computations for symbolic computations for scientific visualizations

SECTION 1: INTRODUCTION. ENGR 112 Introduction to Engineering Computing

Introduction to MATLAB. Simon O Keefe Non-Standard Computation Group

Experiment 1: Introduction to MATLAB I. Introduction. 1.1 Objectives and Expectations: 1.2 What is MATLAB?

What is Matlab? The command line Variables Operators Functions

Matlab notes Matlab is a matrix-based, high-performance language for technical computing It integrates computation, visualisation and programming usin

Matlab is a tool to make our life easier. Keep that in mind. The best way to learn Matlab is through examples, at the computer.

Math 2250 MATLAB TUTORIAL Fall 2005

Digital Image Analysis and Processing CPE

EE168 Handout #6 Winter Useful MATLAB Tips

MATLAB Tutorial. Mohammad Motamed 1. August 28, generates a 3 3 matrix.

MATLAB Basics EE107: COMMUNICATION SYSTEMS HUSSAIN ELKOTBY

INTRODUCTION TO MATLAB PROGRAMMING Lec 1.1: MATLAB Basics

Desktop Command window

the Enter or Return key. To perform a simple computations type a command and next press the

Edward Neuman Department of Mathematics Southern Illinois University at Carbondale

Introduction to Matlab. Summer School CEA-EDF-INRIA 2011 of Numerical Analysis

Introduction to Octave/Matlab. Deployment of Telecommunication Infrastructures

What is MATLAB? What is MATLAB? Programming Environment MATLAB PROGRAMMING. Stands for MATrix LABoratory. A programming environment

! The MATLAB language

Introduction to Matlab. By: Dr. Maher O. EL-Ghossain

Introduction to Computer Programming with MATLAB Matlab Fundamentals. Selis Önel, PhD

LabVIEW MathScript Quick Reference

What is Matlab? A software environment for interactive numerical computations

Arithmetic and Logic Blocks

Creates a 1 X 1 matrix (scalar) with a value of 1 in the column 1, row 1 position and prints the matrix aaa in the command window.

Matlab and Psychophysics Toolbox Seminar Part 1. Introduction to Matlab

INTRODUCTION TO MATLAB

Basic Graphs. Dmitry Adamskiy 16 November 2011

Introduction to MATLAB

What is MATLAB and howtostart it up?

Transcription:

MATLAB Tutorial Lecturer: Keyvan Dehmamy 1

Topics Introduction Running MATLAB and MATLAB Environment Getting help Variables Vectors, Matrices, and linear Algebra Mathematical Functions and Applications Plotting Programming M-files User Defined Functions 2

Introduction What is MATLAB: MATLAB which stands for MATrix LABoratory is a powerful tool for Computation and Visualization in a wide range on science application (From Economy to Aerospace) MATLAB abilities: Variable management Data import and export Calculations (Based on Matrix) Generates Plots and Graphs 3

Running MATLAB Use on Desktop icon or programs path in windows 4

MATLAB Environment Main Working Windows Workspace Windows Current Directory History Windows 5

Getting Help Help Windows Type one of the following commands in the command window: help lists all the help topics help topic provides help for the specified topic help command provides help for the specified command helpwin opens a separate help window for navigation helpwin command doc Display HTML documentation in the Help browser doc command Lookfor keyword search all M-files for keyword 6

Variables Variable names: Must start with a letter (x, y, MyVar, ) May contain only letters, digits, and the underscore _. MATLAB is case sensitive, for example one & ONE are different variables. MATLAB only recognizes the first 31 characters in a variable name. Assignment statement: Variable = number; (x=123;) Variable = expression; (x=y+123;) Effect of ; 7

Variables Special variables: ans: default variable name for the result. pi: = 3.1415926 eps: = 2.2204e-016, smallest value by which two numbers can differ inf:, infinity NAN or nan: not-a-number i and j: imaginary number 1 Commands involving variables: who: lists the names of the defined ed variables ab whos: lists the names and sizes of defined variables clear: clears all variables clear varname: clears the variable name clc: clears the command window clf: clears the current figure and the graph window 8

Vectors MATLAB s calculation is Matrix/vector based. How to create row vector: A=[12 13 pi pi]; or A=[12,13,pi, pi]; How to create column vector: B=[12; 13; pi; -pi]; How to create Matrices: C=[1 2 3;4 5 6; 7 8 9]; Use colon to create special vectores: A=0:0.5:2; A= [0 0.5 1 1.5 2]; A=10:-2:2; A= [10 8 6 4 2]; Vector Transpose: B=A ; 9

Vectors How to access to vectors/matrices elements: A(3), C(2,3), Use of colon (:) notation to access matrices elements: B(1:3), C(:,1:2), C(2:3,:) How to delete a row of a matrix: B(:2)=[];Delete2 B(:,2) 2 nd column B(3,:) = [ ]; Delete 3 rd row How to Concatenation matrices to build a large matrix: B = [AAA] A A]; C=[B [BBBB] B;B B]; 10

Arrays Operations Simply Add(+), Subtract(-), Multiply(*), and Division(/) arrays and scalars. For A/S/M/D of an array by a scalar: B=A+2; B=A-2; B=A*2; B=A/2; Power n of a scalar: C=2; A=C^2; B=C^1 1.3; 11

Arrays Operations Element by Element Operation, dot (.) operator: C=A+B; C=A-B; C=A.*B; C=A./B; C=A.^B Note: A and B Need to be same size or B be scalar! 12

Matrices and Operators Operators: A=B+C; Same Size or one of them be scalar A=B-C; Same Size or one of them be scalar A=B*C; Matched Size or one of them be scalar A=k*B; k is scalar B=inv(A); d=det(a); B=A^2; 13

Matrices and Operators Build a zero filled matrices: A= zeros(n); is an n-by-n matrix of zeros. A= zeros(n,m); is an n-by-m matrix of zeros. Build a one filled matrices: A= ones(n); is an n-by-n matrix of ones. A= ones(n,m); is an n-by-m matrix of ones. Build an Identity matrix: A= eye(n); How get size of matrix: [m,n]=size(a); also m = size(a,1); and n = size(a,2); How to get length of a vector: n = length(a); 14

MATLAB Workspace MATLAB has an interactive programming capability (Not Proposed) Number representation: s e f 1 2 12 13 64 X=±(1+f)*2 e eps = 2-52 realmin = 2-1022 Underflow realmax = (2-eps)2 1023 Overflow 15

MATLAB Workspace format Command format short: Scaled fixed point format with 5 digits. format long: Scaled fixed point format with 15 digits for double and 7 digits for single. format short e: Floating point format with 5 digits. format long e: Floating point format with 15 digits for double and 7 digits for single. format short g: Best of fixed or floating point format with 5 digits. format long g: Best of fixed or floating point format with 15 digits for double and 7 digits for single. format short eng: Engineering format that has at least 5 digits and a power that is a multiple of three format long eng: Engineering format that has exactly 16 significant digits and a power that is a multiple of three. See help format for more information! 16

MATLAB Workspace Directory Manipulation: cd pwd dir mkdir Load and Save command save; Save all variable in matlab.mat files save filename a b c; Save variables a, b, and c in filename.mat load filename; Load a pre-saved file load; Load matlab.mat files 17

Plotting Facility Main command is plot plot(variablename,symbol); plot(1:10, * ) Plotting curves: plot(x,y); x vs. y( (Both Linear) semilogx(x,y); x (Logarithmic scale) vs. y (Linear scale) semilogy(x,y); x (Linear scale) vs. y (Logarithmic scale) loglog(x,y); x vs. y (Both logarithmic scale) Multiple curves plot(x,y,w,z); x vs. y and z vs. w Multiple figures figure(n); Creation a new figure plot() command Close; Closes the figure n window close all; Closes all the plot windows Subplots: subplot(m,n,p); m by n grid of Plots, with p specifying the current plot as the pth window Line type and Color: Plot(x,y, b-,z,w, r.,x,y, k ) 18

Plotting Facility axis Command Command axis([xmin xmax ymin ymax]) Description Define minimum and maximum values of the axes axis square Produce a square plot axis equal Equal scaling factors for both axes axis normal Turn off axis square, equal axis (auto) Return the axis to defaults 19

Plotting Facility Other useful Command Command grid on grid off Grid title( text ) xlabel( text ) ylabel( text ) text(x,y, text ) Description Add dashed grids lines at the tick marks Removes grid lines (default) Toggles grid status (off to on or on to off) Labels top of plot with text Labels horizontal (x) axis with text Labels vertical (y) axis with text Adds text to location (x,y) on the current axes, where (x,y) is in units from the current plot 20

Mathematical Functions Trigonometric: (sin, sind, cos, tan, asin, sinh, ) Exponential: (exp, log, log10, log2, sqrt, nthroot, ) Complex: (imag, real, abs, angle, conj, ) Rounding and Remainder: fix: Round towards zero floor: Round towards minus infinity ceil: Round towards plus infinity round: Round towards nearest integer mod: Modulus after division rem: Remainder after division Discrete Mathematics: (gcd, lcm, factor, factorial, isprime, ) 21

Data Analysis Function Useful command: min: Minimum element from each column of Matrix max: Maximum element from each column of Matrix mean: Mean of each column of Matrix median: Median of each column of Matrix std: Standard Deviation of each column of Matrix sort: Sort a vector prod: Production o of a vector sum: Summation of a vector 22

MATLAB Programming Relational Operators: == (equal to) ~= (not equal) < (less than) <= (less than or equal to) > (greater than) >= (greater than or equal to) Logical Operators: & (and) (or) ~ (not) Logical Function: and, or, xor isempty: A variable is empty or not all, andany: any: All or any of element are nonzero. 23

MATLAB Programming Flow Control: if: if expression statements elseif expression statements else statements end if (a>b), disp( a>b ); end; if (a>b), disp( a>b ); else disp( a<=b ); end; if (a>b), disp( a>b ); elseif (a<b) disp( a<b ); else disp( a=b ); end; 24

MATLAB Programming Flow Control: for: for variable = expr, statement,..., statement end; Cntr = 0; for i=1:100, Cntr = Cntr+i; end; Cntr = 0; for i=100:-2:0, Cntr = Cntr+i; end; Cntr = 0; for i=[1,2,5,12], Cntr = Cntr+i; end; 25

MATLAB Programming Flow Control: while: while expression statements Cntr = 100; while (Cntr>0), end; Cntr = Cntr 1; end; 26

MATLAB Programming Flow Control: Switch-case: case: method = 'Bilinear'; switch lower(method) case { linear, bilinear } disp('method is linear') case 'nearest' disp('method is nearest') otherwise disp('unknown method. ') end; 27

MATLAB Programming m files: script: A set of command in a file, which execute sequentially. function: Like functions in C 28

MATLAB Programming Example of a script: r =100; theta = 12; x=r*cos(theta); y = r*sin(theta); >>Polar2Cart; 29

MATLAB Programming Example of a function: function [x,y] = Polar2Cart(r,theta); x = r*cos(theta); y = r*sin(theta); >>[x,y] = Polar2Cart(r,theta); theta); 30

MATLAB Programming Write help for your function function [x,y] = Polar2Cart(r,theta); theta); % This function convert Polar to Cartesian x = r*cos(theta); % Compute x component. y = r*sin(theta); % Compute y component. 31