Introduction to Matlab. Outline:  What is Matlab? Matlab Screen Variables, array, matrix, indexing Operators (Arithmetic, relational, logical ) Display.

Slides:



Advertisements
Similar presentations
Introduction to MATLAB The language of Technical Computing.
Advertisements

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.
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 Simon O’Keefe Non-Standard Computation Group
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 Οικονομίδης Δημήτρης
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.
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.
MATLAB and SimulinkLecture 11 To days Outline  Introduction  MATLAB Desktop  Basic Features  Branching Statements  Loops  Script file / Commando.
MATLAB Lecture One Monday 4 July Matlab Melvyn Sim Department of Decision Sciences NUS Business School
Matlab tutorial course Lesson 2: Arrays and data types
FOR 520: Geospatial data analysis with Matlab
Martin Ellison University of Warwick and CEPR Bank of England, December 2005 Introduction to MATLAB.
Nonparametric Econometrics1 Intro to Matlab for Data Analysis and Statistical Modeling.
Introduction to MATLAB Session 1 Prepared By: Dina El Kholy Ahmed Dalal Statistics Course – Biomedical Department -year 3.
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
Lecture 4 MATLAB Windows Arithmetic Operators Maintenance Functions
Introduction to MATLAB. Windows in MATLAB Command Window – where you enter data, run MATLAB code, and display results Command History - displays a log.
Objectives Understand what MATLAB is and why it is widely used in engineering and science Start the MATLAB program and solve simple problems in the command.
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)
ECE 1304 Introduction to Electrical and Computer Engineering Section 1.1 Introduction to MATLAB.
Eng Ship Structures 1 Introduction to Matlab.
INTRODUCTION TO MATLAB LAB# 01
1 Lab 2 of COMP 319 Lab tutor : Shenghua ZHONG Lab 2: Sep. 28, 2011 Data and File in Matlab.
Vectors and Matrices In MATLAB a vector can be defined as row vector or as a column vector. A vector of length n can be visualized as matrix of size 1xn.
Getting Started with MATLAB 1. Fundamentals of MATLAB 2. Different Windows of MATLAB 1.
Basics of MATLAB By DR. Wafaa Shabana
Matlab The language of Technical computing Mr. D. Suresh Assistant Professor, Dept. of CSE, PSNA CET, Dindigul.
Introduction to Matlab
Introduction to Matlab. What is Matlab? A software environment for interactive numerical computations Examples:  Matrix computations and linear algebra.
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.
Matlab Tutorial (material available at 1 Dr. Jim Martin Associate Professor School of Computing.
Lecture 20: Choosing the Right Tool for the Job. What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation.
Introduction to Matlab  Matlab is a software package for technical computation.  Matlab allows you to solve many numerical problems including - arrays.
Digital Image Processing Lecture 6: Introduction to M- function Programming.
Digital Image Processing Introduction to M-function Programming.
Introduction to Matlab
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.
1 Faculty Name Prof. A. A. Saati. 2 MATLAB Fundamentals 3 1.Reading home works ( Applied Numerical Methods )  CHAPTER 2: MATLAB Fundamentals (p.24)
SCRIPTS AND FUNCTIONS DAVID COOPER SUMMER Extensions MATLAB has two main extension types.m for functions and scripts and.mat for variable save files.
INTRODUCTION TO MATLAB 1. OUTLINE:  What is Matlab? Matlab Screen Variables, array, matrix, indexing Operators (Arithmetic, relational, logical ) Display.
Introduction to Matlab Engr. Mian Shahzad Iqbal LAB NO.2
Matlab Tutorial (material available at 1 Dr. Jim Martin Associate Professor School of Computing.
MATLAB (Matrix Algebra laboratory), distributed by The MathWorks, is a technical computing environment for high performance numeric computation and.
1 Introduction to Matlab. 2 What is Matlab? Matlab is basically a high level language which has many specialized toolboxes for making things easier for.
What is Matlab?  “MATLAB® is a high-level language and interactive environment for numerical computation, visualization, and programming. Using MATLAB,
Introduction to Matlab. Outline:  What is Matlab? Matlab Screen Variables, array, matrix, indexing Operators.
Introduction to Matlab
Lecture: MATLAB Chapter 1 Introduction
Introduction to MATLAB
MATLAB DENC 2533 ECADD LAB 9.
Introduction to Matlab
Matlab Workshop 9/22/2018.
Introduction To MATLAB
StatLab Matlab Workshop
StatLab Workshop: Intro to Matlab for Data Analysis and Statistical Modeling 11/29/2018.
محاسبات عددی در مهندسی پزشکی جلسه اول و دوم مقدمه ای بر نرم افزار MATLAB گلناز بغدادی 1391.
Introduction to MATLAB [Vectors and Matrices] Lab 2
Introduction to Matlab LAB 4
INTRODUCTION TO MATLAB
Presentation transcript:

Introduction to Matlab

Outline:  What is Matlab? Matlab Screen Variables, array, matrix, indexing Operators (Arithmetic, relational, logical ) Display Facilities Flow Control Using of M-File Writing User Defined Functions Conclusion

What is Matlab? What is MATLAB?  MATLAB provides a language and environment for numerical computation, data analysis, visualisation and algorithm development  MATLAB provides functions that operate on Integer, real and complex numbers Vectors and matrices Structures

What is Matlab? Matlab is basically a high level language which has many specialized toolboxes for making things easier for us How high? Assembly High Level Languages such as C, Pascal etc. Matlab

Matlab Functionality  Built-in Functionality includes Matrix manipulation and linear algebra Data analysis Graphics and visualisation …and hundreds of other functions  Add-on toolboxes provide* Image processing Signal Processing Optimization Genetic Algorithms …* but we have to pay for these extras 

What are we interested in? Matlab is too broad for our purposes in this course. The features we are going to require is Matlab Command Line m-files functions mat-files Command execution like DOS command window Series of Matlab commands Input Output capability Data storage/ loading

1 Starting and stopping To Start  On Windows XP platform select  Start->Programs->Maths and Stats-> MATLAB->MATLAB_local->R2009b->MATLAB R2009b  Start->Programs->MATLAB->R2009b->MATLAB R2009b  For access to the Genetic Algorithms and Stats toolboxes, you must use R2009b on Windows MATLAB runs on Linux quite happily but we do not have toolbox licences To stop (nicely)  Select File -> Exit MATLAB  Or type quit in the MATLAB command window

Matlab Screen Command Window  type commands Current Directory  View folders and m-files Workspace  View program variables  Double click on a variable to see it in the Array Editor Command History  view past commands  save a whole session using diary

Variables No need for types. i.e., All variables are created with double precision unless specified and they are matrices. After these statements, the variables are 1x1 matrices with double precision int a; double b; float c; Example: >>x=5; >>x1=2;

Single Values Singletons  To assign a value to a variable use the equal symbol ‘=‘ >> A = 32  To find out the value of a variable simply type the name in 10

Single Values To make another variable equal to one already entered >> B = A The new variable is not updated as you change the original value Note: using ; suppresses output 11

Single Values The value of two variables can be added together, and the result displayed… >> A = 10 >> A + A …or the result can be stored in another variable >> A = 10 >> B = A + A 12

Array, Matrix a vector x = [ ] x = a matrix x = [1 2 3; 5 1 4; ] x = transpose y = x’ y =

Long Array, Matrix t =1:10 t = k =2:-0.5:-1 k = B = [1:4; 5:8] x =

Generating Vectors from functions zeros(M,N)MxN matrix of zeros ones(M,N)MxN matrix of ones rand(M,N)MxN matrix of uniformly distributed random numbers on (0,1) x = zeros(1,3) x = x = ones(1,3) x = x = rand(1,3) x =

Matrix Index The matrix indices begin from 1 (not 0 (as in C)) The matrix indices must be positive integer Given: A(-2), A(0) Error: ??? Subscript indices must either be real positive integers or logicals. A(4,2) Error: ??? Index exceeds matrix dimensions.

Concatenation of Matrices x = [1 2], y = [4 5], z=[ 0 0] A = [ x y] B = [x ; y] C = [x y ;z] Error: ??? Error using ==> vertcat CAT arguments dimensions are not consistent.

Operators (arithmetic) +addition -subtraction *multiplication /division ^power ‘complex conjugate transpose

Matrices Operations Given A and B: AdditionSubtractionProductTranspose

Operators (Element by Element).*element-by-element multiplication./element-by-element division.^element-by-element power

The use of “.” – “Element” Operation K= x^2 Erorr: ??? Error using ==> mpower Matrix must be square. B=x*y Erorr: ??? Error using ==> mtimes Inner matrix dimensions must agree. A = [1 2 3; 5 1 4; 3 2 1] A = y = A(3,:) y= b = x.* y b= c = x. / y c= d = x.^2 d= x = A(1,:) x= 1 2 3

Basic Task: Plot the function sin(x) between 0 ≤ x ≤4π Create an x-array of 100 samples between 0 and 4 π. Calculate sin(.) of the x-array Plot the y-array >>x=linspace(0,4*pi,100); >>y=sin(x); >>plot(y)

Plot the function e -x/3 sin(x) between 0 ≤ x ≤4π Create an x-array of 100 samples between 0 and 4 π. Calculate sin(.) of the x-array Calculate e -x/3 of the x-array Multiply the arrays y and y1 >>x=linspace(0,4*pi,100); >>y=sin(x); >>y1=exp(-x/3); >>y2=y*y1;

Plot the function e -x/3 sin(x) between 0 ≤ x ≤4π Multiply the arrays y and y1 correctly Plot the y2-array >>y2=y.*y1; >>plot(y2)

Display Facilities plot(.) stem(.) Example: >>x=linspace(0,4*pi,100); >>y=sin(x); >>plot(y) >>plot(x,y) Example: >>stem(y) >>stem(x,y)

Display Facilities title(.) xlabel(.) ylabel(.) >>title(‘This is the sinus function’) >>xlabel(‘x (secs)’) >>ylabel(‘sin(x)’)

Operators (relational, logical) == Equal to ~= Not equal to < Strictly smaller > Strictly greater <= Smaller than or equal to >= Greater than equal to & And operator | Or operator

Flow Control if for while break ….

Control Structures If Statement Syntax if (Condition_1) Matlab Commands elseif (Condition_2) Matlab Commands elseif (Condition_3) Matlab Commands else Matlab Commands end Some Dummy Examples if ((a>3) & (b==5)) Some Matlab Commands; end if (a<3) Some Matlab Commands; elseif (b~=5) Some Matlab Commands; end if (a<3) Some Matlab Commands; else Some Matlab Commands; end

Control Structures For loop syntax for i=Index_Array Matlab Commands end Some Dummy Examples for i=1:100 Some Matlab Commands; end for j=1:3:200 Some Matlab Commands; end for m=13:-0.2:-21 Some Matlab Commands; end for k=[ ] Some Matlab Commands; end

Control Structures While Loop Syntax while (condition) Matlab Commands end Dummy Example while ((a>3) & (b==5)) Some Matlab Commands; end

Use of M-File Click to create a new M-File Extension “.m” A text file containing script or function or program to run

Use of M-File If you include “;” at the end of each statement, result will not be shown immediately Save file as Denem430.m

Writing User Defined Functions Functions are m-files which can be executed by specifying some inputs and supply some desired outputs. The code telling the Matlab that an m-file is actually a function is You should write this command at the beginning of the m-file and you should save the m-file with a file name same as the function name function out1=functionname(in1) function out1=functionname(in1,in2,in3) function [out1,out2]=functionname(in1,in2)

Writing User Defined Functions Examples  Write a function : out=squarer (A, ind) Which takes the square of the input matrix if the input indicator is equal to 1 And takes the element by element square of the input matrix if the input indicator is equal to 2 Same Name

Writing User Defined Functions Another function which takes an input array and returns the sum and product of its elements as outputs The function sumprod(.) can be called from command window or an m-file as

Notes: “%” is the neglect sign for Matlab (equaivalent of “//” in C). Anything after it on the same line is neglected by Matlab compiler. Sometimes slowing down the execution is done deliberately for observation purposes. You can use the command “pause” for this purpose pause %wait until any key pause(3) %wait 3 seconds

Useful Commands The two commands used most by Matlab users are >>help functionname >>lookfor keyword

Questions ?

Thank You…