Introduction to Matlab Patrice Koehl Department of Biological Sciences National University of Singapore

Slides:



Advertisements
Similar presentations
StatLab Workshop Yale University Maximiliano Appendino, Economics October 18 th, 2013.
Advertisements

Introduction to MATLAB The language of Technical Computing.
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 ME1107 Y Yan Reference: MATLAB for Engineers by Holly Moore (Pearson Prentice Hall)
Introduction to MATLAB Week 13 – 4/21/09. Instructor: Kate Musgrave Time: Tuesdays 3-5pm Office Hours: Tuesdays 1:30-3pm
Digital Image Processing Lecture3: Introduction to MATLAB.
1 MATLAB 基礎. 2 MATLAB  Workspace: environment (address space) where all variables reside  After carrying out a calculation, MATLAB assigns the result.
MATLAB Lecture One Monday 4 July Matlab Melvyn Sim Department of Decision Sciences NUS Business School
1 Statistical Computing in MATLAB AMS 597 Ling Leng.
BRIAN D. HAHN AND DANIEL T. VALENTINE THIRD EDITION Essential MATLAB® for Engineers and Scientists.
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.
Computer Science 111 Fundamentals of Programming I Overview of Programming.
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.
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.
Computational Methods of Scientific Programming Lecturers Thomas A Herring, Room A, Chris Hill, Room ,
INTRODUCTION TO MATLAB LAB# 01
1 Computer Programming (ECGD2102 ) Using MATLAB Instructor: Eng. Eman Al.Swaity Lecture (1): Introduction.
Chapter 1: Getting Started with MATLAB MATLAB for Scientist and Engineers Using Symbolic Toolbox.
Advanced Topics- Functions Introduction to MATLAB 7 Engineering 161.
MATLAB Environment ELEC 206 Computer Applications for Electrical Engineers Dr. Ron Hayne.
Scientific Computing Introduction to Matlab Programming.
Beginning Programming for Engineers Introduction to Programming and Computer Science.
OUTLINE Overview Numbers, variables and similar in Matlab
Chapter 6 Review: User Defined Functions Introduction to MATLAB 7 Engineering 161.
Computer Simulation Lab Electrical and Computer Engineering Department SUNY – New Paltz SUNY-New Paltz “Lecture 2”
Lecture 20: Choosing the Right Tool for the Job. What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation.
Lecture 26: Reusable Methods: Enviable Sloth. Creating Function M-files User defined functions are stored as M- files To use them, they must be in the.
Interduction to MATLAB Manal Alotaibi Mathematics department College of science King saud university.
Introduction to Matlab  Matlab is a software package for technical computation.  Matlab allows you to solve many numerical problems including - arrays.
訊號與系統 廖文淵 德霖技術學院資訊工程系 Introduction to MATLAB.
Introduction to MATLAB 1.Basic functions 2.Vectors, matrices, and arithmetic 3.Flow Constructs (Loops, If, etc) 4.Create M-files 5.Plotting.
ECE 351 M ATLAB I NTRODUCTION ( BY T EACHING A SSISTANTS )
BRIAN D. HAHN AND DANIEL T. VALENTINE THIRD EDITION Essential MATLAB® for Engineers and Scientists.
The MatLab Language Mathematics Laboratory The MathWorks
M ATLAB – What Is It ? Name is from matrix laboratory Powerful tool for – Computation and visualization of engineering and science mathematics – Communication.
MATLAB Lecture 1 염익준. Introduction MATLAB (MATrix LABoratory) a special purpose computer program optimized to perform engineering and scientific calculations.
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.
Math 252: Math Modeling Eli Goldwyn Introduction to MATLAB.
Introduction to Programming on MATLAB Ecological Modeling Course Sep 11th, 2006.
Matlab Tutorial Iman Moazzen First Session – September 11, 2013.
CIS 595 MATLAB First Impressions. MATLAB This introduction will give Some basic ideas Main advantages and drawbacks compared to other languages.
An Introduction to Programming in Matlab Emily Blumenthal
MATLAB (Matrix Algebra laboratory), distributed by The MathWorks, is a technical computing environment for high performance numeric computation and.
전자장 1 실험 - Matlab 사용법 - Photonic Systems Laboratory School of EE, Seoul National University Photonic Systems Lab School of EECS, S.N.U.
M ATLAB – What Is It ? Name is from matrix laboratory Powerful tool for – Computation and visualization of engineering and science mathematics – Communication.
Introduction to Matlab
Lecture: MATLAB Chapter 1 Introduction
Statistical Computing in MATLAB
MATLAB Basics Nafees Ahmed Asstt. Professor, EE Deptt DIT, DehraDun.
Introduction to MATLAB
INTRODUCTION TO BASIC MATLAB
MATLAB DENC 2533 ECADD LAB 9.
Matlab Workshop 9/22/2018.
MATH 493 Introduction to MATLAB
Use of Mathematics using Technology (Maltlab)
MATLAB – What Is It ? Name is from matrix laboratory Powerful tool for
MATLAB – What Is It ? Name is from matrix laboratory Powerful tool for
StatLab Workshop: Intro to Matlab for Data Analysis and Statistical Modeling 11/29/2018.
MATLAB – What Is It ? Name is from matrix laboratory Powerful tool for
Digital Image Processing
Communication and Coding Theory Lab(CS491)
CSCI N317 Computation for Scientific Applications Unit 1 – 1 MATLAB
Experiment No. (1) - an introduction to MATLAB
Introduction To MATLAB
Presentation transcript:

Introduction to Matlab Patrice Koehl Department of Biological Sciences National University of Singapore

What is MATLAB?  A high-performance language for technical computing (Mathworks, 1998)  The name is derived from MATrix Laboratory  Typical uses of MATLAB Mathematical computations Algorithmic development Model prototyping Data analysis and exploration of data (visualization) Scientific and engineering graphics for presentation

Why Matlab?  Because it simplifies the analysis of mathematical models  It frees you from coding in high-level languages (saves a lot of time - with some computational speed penalties)  Provides an extensible programming/visualization environment  Provides professional looking graphs

Matlab  The Matlab Environment  Variables; operations on variables  Programming  Visualization

Matlab  The Matlab Environment  Variables; operations on variables  Programming  Visualization

The Matlab Environment Command Window Workspace Command history Current folder

Help in Matlab Help Browser -> Product Help Command line: >> help Example: >> help sqrt

Matlab  The Matlab Environment  Variables; operations on variables  Programming  Visualization

 Begin with an alphabetic character: a  Case sensitive: a, A  No data typing: a=10; a=‘OK’; a=2.5  Default output variable: ans  Built-in constants: pi i j Inf  clear removes variables  who lists variables  whos list variables and gives size  Special characters : [] () {} ; % : Variables in Matlab

 Row vectors >> R1 = [ ] >> R2 = [1 : 5] >> R3 = [-pi : pi/3 : pi]  Column vectors >> C1 = [1; 2; 3; 4; 5] >> C2 = R2' Vectors in Matlab

Matrices in Matlab  Creating a matrix >> A = [ ; pi 4] >> A = [R1; R2] >> A = zeros(10,5) >> A = ones(10,5) >> A = eye(10)  Accessing elements >> A(1,1) >> A(1:2, 2:4) >> A(:,2)

 Operators + and – >> X = [1 2 3] >> Y = [4 5 6] >> A = X + Y A=  Operators *, /, and ^ >> Ainv = A^-1 Matrix math is default! Matrix Operations

Element wise operations Operators.*,./, and.^ >> Z = [2 3 4]’ >> B = [Z.^2 Z Z.^0] B=

Matlab  The Matlab Environment  Variables; operations on variables  Programming  Visualization

 Script M-Files  Automate a series of steps.  Share workspace with other scripts and the command line interface.  Function M-Files  Extend the MATLAB language.  Can accept input arguments and return output arguments.  Store variables in internal workspace. M-file programming

 Always has one script M-File  Uses built-in and user-defined functions  Created in MATLAB Editor >> edit model.m  Run from Command Line Window >> model M-file programming

Example of script

Example of function

Input / Output  Get input from command window: >> num = input(‘What is the altitude :’) >> str = input(‘Enter name of the planet’,’s’)  Display output in command window: String >> disp(‘The answer is:’) String + number: >> disp([‘The value of x is: ‘ num2str(x)])

Operators

Program flow control: For Simple program that sums the squares of all the elements of a matrix A: N = 10; M = 20; A = rand(10,20) Sum = 0; for i = 1:N for j = 1:M Sum = Sum + A(i,j)^2; end Note that this can be done in one line: Sum2 = sum(sum(A.*A));

Program flow control: if Simple program that compares two numbers a and b: set j to 1 if a>b, -1 if a<b, and 0 if a = b: if a > b j = 1; else if a < b j = -1; else j = 0; end

 Workspace >> clear >> who >> whos >> close  File operations >> ls >> dir >> cd >> pwd >> mkdir Other useful commands

Matlab  The Matlab Environment  Variables; operations on variables  Programming  Visualization

References Violeta Ivanova, MIT Experiment with Matlab (Steve Moler): Matlab: learning by examples