MATLAB TUTORIAL Dmitry Drutskoy Some material borrowed from the departmental MATLAB info session by Philippe Rigollet Kevin Wayne.

Slides:



Advertisements
Similar presentations
Lab # 03- SS Basic Graphic Commands. Lab Objectives: To understand M-files principle. To plot multiple plots on a single graph. To use different parameters.
Advertisements

Introduction to MATLAB The language of Technical Computing.
Introduction to M ATLAB Programming Ian Brooks Institute for Climate & Atmospheric Science School of Earth & Environment
Statistical Methods Lynne Stokes Department of Statistical Science Lecture 7: Introduction to SAS Programming Language.
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.
MATLAB - Basics Centro de Informática Universidade Federal de Pernambuco Aprendizagem de Máquina – IN1102 Arley Ristar –
Soft Computing 1 Matlab Tutorial Kai Goebel, Bill Cheetham RPI/GE CRD
Introduction to Matlab By: Dr. Maher O. EL-Ghossain.
EGR 106 – Week 2 – Arrays & Scripts Brief review of last week Arrays: – Concept – Construction – Addressing Scripts and the editor Audio arrays Textbook.
General Computer Science for Engineers CISC 106 Lecture 08 Dr. John Cavazos Computer and Information Sciences 2/27/2009.
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.
Chapter 4 MATLAB Programming Combining Loops and Logic Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
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
Data, graphics, and programming in R 28.1, 30.1, Daily:10:00-12:45 & 13:45-16:30 EXCEPT WED 4 th 9:00-11:45 & 12:45-15:30 Teacher: Anna Kuparinen.
Lecture 4 MATLAB Windows Arithmetic Operators Maintenance Functions
ELG 3120 Signal and System Analysis 1 Introduction to MATLAB TAs Wei Zhang Ozgur Ekici (Section A)(Section B) ELG 3120 Lab Tutorial 1.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. A Concise Introduction to MATLAB ® William J. Palm III.
Introduction to MATLAB CBE 502 Mathematical Methods of Engineering Analysis.
MEGN 536 – Computational Biomechanics MATLAB: Getting Started Prof. Anthony J. Petrella Computational Biomechanics Group.
A Brief Introduction to Matlab Laila Guessous Dept. of Mechanical Engineering Oakland University.
COMP 116: Introduction to Scientific Programming Lecture 6: Scripts and publishing, Creating matrices.
Matlab Workshop 1/10/07 Lesson 1: Matlab as a graphing calculator.
Numerical Computation Lecture 2: Introduction to Matlab Programming United International College.
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.
COMP 116: Introduction to Scientific Programming Lecture 5: Plotting, Scripts and publishing.
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.
MAE 1202: AEROSPACE PRACTICUM An Introduction to MATLAB: Part 2 Mechanical and Aerospace Engineering Department Florida Institute of Technology Developed.
Scientific Computing Introduction to Matlab Programming.
Matlab Basics FIN250f: Lecture 3 Spring 2010 Grifths Web Notes.
Master in Optical Fiber Communications and Photonic Technologies Foundations of Digital Transmission - Fall quarter Introduction to Matlab.
MA/CS 375 Fall 2002 Lecture 3. Example 2 A is a matrix with 3 rows and 2 columns.
Matlab Screen  Command Window  type commands  Current Directory  View folders and m-files  Workspace  View program variables  Double click on a.
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.
Introduction to Matlab  Matlab is a software package for technical computation.  Matlab allows you to solve many numerical problems including - arrays.
Introduction to MATLAB Session 2 Simopekka Vänskä, THL Department of Mathematics and Statistics University of Helsinki 2010.
Introduction to MATLAB 1.Basic functions 2.Vectors, matrices, and arithmetic 3.Flow Constructs (Loops, If, etc) 4.Create M-files 5.Plotting.
September 15, 2005 Lecture 5 - By Paul Lin 1 CPET 190 Lecture 5 Problem Solving with MATLAB
ECE 351 M ATLAB I NTRODUCTION ( BY T EACHING A SSISTANTS )
Introduction to Matlab Patrice Koehl Department of Biological Sciences National University of Singapore
SCRIPTS AND FUNCTIONS DAVID COOPER SUMMER Extensions MATLAB has two main extension types.m for functions and scripts and.mat for variable save files.
Math 252: Math Modeling Eli Goldwyn Introduction to MATLAB.
Matlab Tutorial Iman Moazzen First Session – September 11, 2013.
CS100A, Fall 1998, Lecture 191 CS100A, Fall 1998 Lecture 19, Thursday Nov 05 Matlab Concepts: Matlab arrays Matlab subscripting Matlab plotting.
CS100A, Fall 1998, Lecture 201 CS100A, Fall 1998 Lecture 20, Tuesday Nov 10 More Matlab Concepts: plotting (cont.) 2-D arrays Control structures: while,
Machine Learning Octave tutorial 데이터 마이닝 박 영 택.
Outline What is MATLAB MATLAB desktop Variables, Vectors and Matrices Matrix operations Array operations Built-in functions: Scalar, Vector, Matrix Data.
How to use MATLAB (using M-files) Double click this icon To start Matlab 6.5.
Some “What’s the output” questions to get the day started… >>A = [1 2 3; 3 5 6] This statement stores the matrix: 1. A= 2. A= 3. A= 4. A= Ask Garvin’s.
Introduction to MATLAB
응용 전산 및 실습 MATLAB – Chapter 3 행렬연산
Computer Application in Engineering Design
Introduction to Matlab
Scripts & Functions Scripts and functions are contained in .m-files
MATLAB DENC 2533 ECADD LAB 9.
Matlab Workshop 9/22/2018.
StatLab Matlab Workshop
MATH 493 Introduction to MATLAB
Use of Mathematics using Technology (Maltlab)
StatLab Workshop: Intro to Matlab for Data Analysis and Statistical Modeling 11/29/2018.
MATLAB How to use (using M-files)
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.
Announcements P3 due today
How to Use MATLAB A Brief Introduction.
Matlab Basics Tutorial
Presentation transcript:

MATLAB TUTORIAL Dmitry Drutskoy Some material borrowed from the departmental MATLAB info session by Philippe Rigollet Kevin Wayne

Overview Getting MATLAB set up Scalar/matrix creation and operations MATLAB programming Plotting

Installation Princeton has a license for all students to use MATLAB, even on personal computers. You have to be on the university network; It takes your university username/password. Instructions are available.

Working Directory Default location is C:\Users\ \Documents\MATLAB Type ‘pwd’ or use the current folder window. For each project, create a new directory for simplicity. Change directory to the new one, all new files created will be stored here. MATLAB automatically finds functions in current directory files.

Finding help Click the fx symbol next to your current command line for help on functions Use “help ” or “doc ” for the function If everything else fails, google it!

Basic Scalars/Matrices

More matrices

Using the : symbol

Special Matrices eye(n) is the identity matrix of size n x n. zeros(m, n) is the m x n matrix with only zeroes. ones(m, n) is the m x n with only 1’s. magic(n) gives a n x n matrix with integer coefficients from 1 to n² with equal column and row sums.

Random Matrices rand(m, n) is a matrix of size m by n with independent entries that are uniformly distributed on the interval [0, 1] randn(m, n) is a matrix of size m by n with independent entries that are normally distributed rand(n) and randn(n) return square matrices of size n by n.

Matrix Operations

Matrix Operations cont. null(A) is an orthogonal basis for the null space of A sum(A) returns a row vector containing the sum of the columns of A.

Logical Operations Tests such as A < b return logical values These can be manipulated as regular integers (1 for true, 0 for false). find will return all the elements for which a condition is true: find([1, 2, 3] > 1) returns [2, 3]

Logical Operations cont. [v, id] = max(a) returns the maximum element of the vector a and the corresponding indices in id. [s, id] = sort(a) returns the elements of a sorted in ascending order and the permutation id such that s(id) is increasing.

Usual Functions Mathematics: sin, cos, exp, log, log10, sqrt, ceil, floor, round,... Information: size, length, who, whos, ls Management: save, load, clear save filename x y A load filename

Writing functions File -> new -> function Functions/scripts/classes are all.m files, but different semantics. To be able call functions, place them in your project directory. function [ output_args ] = Silly( input_args ) %SILLY Summary of this function goes here % Detailed explanation goes here end

Programming Logic if, else statements: for statements can be used too: Similar behavior for repeat, until, while, etc. if (a > 1) blah else blahblah end for i=1:n moreblah end

Function parameters To input values, use the as many arguments after the function name as you need, then use them in your program. function [ output1, output2 ] = Silly( input1, input2) some_value = input1*input2; Output values must be set before the “end” statement. output1 = some_value; output2 = 15.7; end

Calling Functions Note that the type of input1, input2 is not set anywhere. Can be scalars, vectors, matrices… To call this function with 2 return values, do: This will save output1 as a and output2 as b. If we specify fewer return parameters, the first few are used. [a, b] = Silly(5, 7); [a, b] = Silly(vector1, vector2);

Scripts You should write all you commands in a script using the editor. Use F5 to run the script. Using the name of the script from the command line works too. Use F9 to run the current selection. CTRL-i will automatically (and correctly) indent the current selection. CTRL-R will comment the current selection, CTRL-T will uncomment it (useful to test only parts of a code).

Plotting plot(x, y) will plot a function that takes values y = (y1,..., yn) at the points x = (x1,..., xn). Use xlabel(′ALabelForX′) and ylabel(′ALabelForY ′) to put labels on the axes and Title(′ATitle′) to include a title. plot(x1, y1, ':bo', x2, y2, '-r.') will plot two curves, one as a blue dotted line with circles at each point, the other red continuous with dots.

Plotting cont. Look for ”Linespec” in the MATLAB documentation to find other codes for line colors, markers, etc. Use legend(′plot1′,′ plot2′,...) to include a legend. To combine plots: use hold on after the first one and hold off after the last plot. hold on plot (x1, y1, ':bo') plot (x2, y2, '-r.') hold off