Introduction to MATLAB for Biomedical Engineering BME 1008 Introduction to Biomedical Engineering FIU, Spring 2015 Lesson 2: Element-wise vs. matrix operations.

Slides:



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

Introduction to M ATLAB Programming Ian Brooks Institute for Climate & Atmospheric Science School of Earth & Environment
Introduction to Engineering MATLAB – 11 Plotting - 4 Agenda Multiple curves Multiple plot.
Introduction to Matlab
Introduction to MATLAB
Introduction to Matlab Workshop Matthew Johnson, Economics October 17, /13/20151.
MATLAB – What is it? Computing environment / programming language Tool for manipulating matrices Many applications, you just need to get some numbers in.
Introduction to Matlab EE 2303 Lab. MATLAB stands for “Matrix Laboratory” APPLICATIONS OF MATLAB:  Mathematical Calculations  Data Analysis & Visualization.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 19P. 1Winter Quarter MATLAB: Script and.
Soft Computing 1 Matlab Tutorial Kai Goebel, Bill Cheetham RPI/GE CRD
MATLAB ME1107 Y Yan Reference: MATLAB for Engineers by Holly Moore (Pearson Prentice Hall)
Introduction to Matlab By: Dr. Maher O. EL-Ghossain.
Introduction to Matlab Tutorial for CS4MN3/SE3X03 Wen Yu McMaster University.
Dr. Jie Zou PHY Welcome to PHY 3320 Computational Methods in Physics and Engineering.
Introduction to MATLAB MECH 300H Spring Starting of MATLAB.
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.
Matlab intro The Environment
Introduction to MATLAB ENGR 1187 MATLAB 1. Programming In The Real World Programming is a powerful tool for solving problems in every day industry settings.
1 MATLAB 基礎. 2 MATLAB  Workspace: environment (address space) where all variables reside  After carrying out a calculation, MATLAB assigns the result.
1 Introduction to MATLAB MATLAB is all of the following: 1.Computational environment 2.Plotting software 3.Programming language Typical applications: 1.Calculations.
Mathcad Variable Names A string of characters (including numbers and some “special” characters (e.g. #, %, _, and a few more) Cannot start with a number.
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 1. Outline: What is Matlab? Matlab Screen Variables, array, matrix, indexing Operators Plotting Flow Control Using of M-File Writing.
REVIEW 2 Exam History of Computers 1. CPU stands for _______________________. a. Counter productive units b. Central processing unit c. Copper.
ELG 3120 Signal and System Analysis 1 Introduction to MATLAB TAs Wei Zhang Ozgur Ekici (Section A)(Section B) ELG 3120 Lab Tutorial 1.
Introduction to MATLAB CBE 502 Mathematical Methods of Engineering Analysis.
MEGN 536 – Computational Biomechanics MATLAB: Getting Started Prof. Anthony J. Petrella Computational Biomechanics Group.
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.
MATLAB An Introduction to MATLAB (Matrix Laboratory) 1.
MATLAB Tutorial EE 327 Signals and Systems 1. What is MATLAB? MATLAB – Matrix Laboratory The premier number-crunching software Extremely useful for signal.
INTRODUCTION TO MATLAB LAB# 01
Matlab Basics Tutorial. Vectors Let's start off by creating something simple, like a vector. Enter each element of the vector (separated by a space) between.
Chapter 1: Getting Started with MATLAB MATLAB for Scientist and Engineers Using Symbolic Toolbox.
Matlab Programming for Engineers Dr. Bashir NOURI Introduction to Matlab Matlab Basics Branching Statements Loops User Defined Functions Additional Data.
10/24/20151 Chapter 2 Review: MATLAB Environment Introduction to MATLAB 7 Engineering 161.
MATLAB Environment ELEC 206 Computer Applications for Electrical Engineers Dr. Ron Hayne.
Lecture 2 - Matlab Introduction CVEN 302 June 5, 2002.
Introduction to MATLAB ENGR 1181 MATLAB 1. Opening MATLAB  Students, please open MATLAB now.  CLICK on the shortcut icon → Alternatively, select… start/All.
Introduction to Matlab. Outline:  What is Matlab? Matlab Screen Variables, array, matrix, indexing Operators (Arithmetic, relational, logical ) Display.
Introduction to Matlab. What is Matlab? A software environment for interactive numerical computations Examples:  Matrix computations and linear algebra.
Matlab Screen  Command Window  type commands  Current Directory  View folders and m-files  Workspace  View program variables  Double click on a.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Introduction to MATLAB 7 for Engineers William J. Palm.
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.
Introduction to Matlab  Matlab is a software package for technical computation.  Matlab allows you to solve many numerical problems including - arrays.
Array Operations ENGR 1181 MATLAB 4.
Introduction to Matlab
EGR 115 Introduction to Computing for Engineers MATLAB Basics 3: Array Operations Monday 08 Sept 2014 EGR 115 Introduction to Computing for Engineers.
INTRODUCTION TO MATLAB DAVID COOPER SUMMER Course Layout SundayMondayTuesdayWednesdayThursdayFridaySaturday 67 Intro 89 Scripts 1011 Work
The Hong Kong Polytechnic University Industrial Centre MatLAB Lesson 1 : Overview & Environment Edward Cheung Room W311g.
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.
Introduction to Matlab Patrice Koehl Department of Biological Sciences National University of Singapore
1 Faculty Name Prof. A. A. Saati. 2 MATLAB Fundamentals 3 1.Reading home works ( Applied Numerical Methods )  CHAPTER 2: MATLAB Fundamentals (p.24)
Math 252: Math Modeling Eli Goldwyn Introduction to MATLAB.
Introduction to Programming on MATLAB Ecological Modeling Course Sep 11th, 2006.
Project Teams Project on Diffusion will be a TEAM project. 34 Students in class so 6 teams of 5 and one Team of 4. Determine members of team and a team.
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.
Introduction to Matlab. Outline:  What is Matlab? Matlab Screen Variables, array, matrix, indexing Operators.
ECE 1304 Introduction to Electrical and Computer Engineering
Introduction to Matlab
MATLAB DENC 2533 ECADD LAB 9.
MATH 493 Introduction to MATLAB
Introduction to MATLAB [Vectors and Matrices] Lab 2
Matlab Basics Tutorial
Chapter 2 MATLAB Environment
Presentation transcript:

Introduction to MATLAB for Biomedical Engineering BME 1008 Introduction to Biomedical Engineering FIU, Spring 2015 Lesson 2: Element-wise vs. matrix operations save(), load(), matlab script plot(x,y)

Creating Vectors (1D arrays) Explicit list of elements >> x1 = [ ] x = Using colon (:) notation >> x2 = -2 : 5 x2 =

General colon (:) syntax: initial value : increment : final value >> x3 = 1:1.5:6 x3 = >> x4 = 1:6 %default increment 1 x4 =

In matrix algebra In MATLAB A*B means matrix product A.* B means element-by-element multiplication '. ' (dot) - indicates element-by-element operation Matrix product C = AB

Element-wise (array) operators: +, -,.*,./,.^ '+ ' - addition always element wise >> x1 = [1 2 3]; x2 = [4 5 6]; >> x1 + x2 ans = >> x ans =

>> x1 + [10 20] ??? Error using ==> plus Matrix dimensions must agree. '- ' - subtraction always element wise >> x1 = [1 2 3]; x2 = [4 5 6]; >> x1 - x2 ans = >> 3 - x1 ans = 2 1 0

'.* ' - element-wise multiplication >> x1 = [1 2 3]; x2 = [4 5 6]; >> x1.* x2 ans = >> x1 * 10 ans = >> x1*x2 ??? Error using ==> mtimes Inner matrix dimensions must agree.

'./ ' - element-wise multiplication >> x1 = [1 2 3]; x2 = [4 5 6]; >> x1./ x2 ans = >> 1./x1 ans = >> 1/x1 ??? Error using ==> mrdivide Matrix dimensions must agree.

'.^ ' - element-wise power >> A = [5 1 -2]; >> A.^ 3 ans = >> A ^ 3 ??? Error using ==> mpower Matrix must be square.

Matrix operators *, ^ >> x1 = [1 2 3]; %row vector x1 = 123 >> x2 = [4 5 6]'; %column vector x2 = >> x1*x2 %matrix multiplication ans = 32

>> x1 = [1 2; 3 4] % 2-by-2 matrix x1 = >> x1^2 % or x1*x1 ans = %matrix product

Quiz 1 1) What is the average of: 1 3, 1.5 3, 2 3, , , 12 3 ? Hint: First create vector, then cube. 2) What is the maximum element of C, where Hint: Use max() two times.

Answers to Quiz 1 1) >> x = [1:0.5:12]; y = x.^3; >> average = mean(y) average =

2) >> A=[30 5.5; 2 -7]; B=[-3 6; 8 12]; >> C = A*B C = >> max(C) %returns max. element from each column ans = >> max(max(C)) %returns max. element from C ans = 246

Matlab Scalar functions sin(), cos(), exp(), log(), log10() operate element-wise >> t = [0 : pi/2: 2*pi ] % pi = 3.14 Matlab constant t = >> y = sin(t) y = >> e = exp([0 1 -1]) %exponential function e =

SAVE & LOAD Commands save('filename') saves all workspace variables to disk in current directory in the file 'filename.mat' '.mat' - default extension for Matlab binary file (MAT-file) save('filename','var1','var2') saves only variables 'var1' and 'var2' load('filename') loads workspace variables from disk from the file 'filename.mat'

>> clear %removes variables from workspace >> x = [0: 0.1 : 1000]; >> y = exp(-x/500); % x, y vectors with elements >> save('myResults') >> save('myResults_y','y') >> clear >> whos >> load('myResults') >> whos

Manual Loading & Saving

Importing data from other file formats (.txt,.xls,.jpg,...)

Matlab script text file with a series of Matlab commands Matlab program with no input and output arguments has extension '.m' (M-file) (1) New or Open (2) Edit in Matlab editor (4) Run(3) Save

plot(x,y) command % Moore's Law -transistor count double every two years transistors= [ ]; years=[2000:1.5:2012]; plot(years, transistors)

plot(years, transistors,'r*--') %'r*--' red, star, dashed line ylabel('transistor count (million)') % y-axis label xlabel('year') % x-axis label title('Moore''s law')

Figure editing (1) Edit plot (3) Change properties (2) Select object (line, axis, label)

Saving figures '.fig' file, Matlab format, figure can be edited as image file, e.g. '.bmp'

Copy & Paste figure to Word or PPT

Quiz 2 Given y = sin(x) × e -x/15 and x = [0:0.2:10*pi] hint: exp() max() plot y vs. x find maximum y

Answer to Quiz 2 >> x = [0:0.2:10*pi]; >> y = sin(x).*exp(-x/15); >> figure %opens new figure window >> plot(x,y) >> y_max = max(y) y_max =