CMU CS 15780 - MATLAB Tutorial (8 pages)

Previewing pages 1, 2, 3 of 8 page document View the full content.
View Full Document

MATLAB Tutorial



Previewing pages 1, 2, 3 of actual document.

View the full content.
View Full Document
View Full Document

MATLAB Tutorial

148 views


Pages:
8
School:
Carnegie Mellon University
Course:
Cs 15780 - Graduate Artificial Intelligence
Unformatted text preview:

Contents What is Matlab Matrices MATLAB Tutorial Numerical Arrays String Arrays Elementary Math Based on IPLab SUT Matlab Tutorial 1 Logical Operators Math Functions Importing and Exporting Data 2 Contents What is MATLAB Continued Graphics Fundamentals high performance software 2D plotting Subplots 3D plotting Computation Visualization Easy to use environment Editing and Debugging M files high level language Script and Function Files Basic Parts of an M file Flow Control Statements M file Programming Data Types 3 Data types Functions Control flow statements Input output Graphics Object oriented programming capabilities 5 Calculations at the Command Line MATLAB as a calculator 5 4 8 5 32 2 5 4 8 5 32 2 ans ans 0 0488 0 0488 3 4i 3 4i 3 4i 3 4i ans ans 25 25 cos pi 2 cos pi 2 ans ans 6 1230e 017 6 1230e 017 exp acos 0 3 exp acos 0 3 ans ans 3 5470 3 5470 General Functions Assigning Variables aa 2 2 bb 5 5 a b a b Semicolon suppresses screen output ans ans 32 32 Results assigned to ans if name not specified xx 5 2 pi 5 2 pi yy sin x sin x yy 11 zz asin y asin y zz whos List current variables clear Clear variables and functions from memory cd Change current working directory ls List files in directory parentheses for function inputs 1 5708 1 5708 9 A Note about Workspace Numbers stored in double precision floating point format 10 1 Getting help Matrices help command lookfor command Printable Documents help lookfor Matlabroot help pdf doc 11 12 The Matrix in MATLAB Entering Numeric Arrays a 1 a 1 2 3 2 3 4 4 aa 11 33 Row separator semicolon Use square brackets 22 44 1 A b 2 8 b 2 8 sqrt 7 sqrt 7 3 5 6 3 4 3 5 6 3 4 bb 2 8000 2 8000 00 2 6458i 2 6458i Column separator b 2 5 23 b 2 5 23 space comma Any MATLAB expression can be entered as a matrix element Matrices must be rectangular Set undefined elements to zero Creating sequences colon operator Utility functions for creating matrices 15 0 6068 0 6068 0 4860 0 4860 1 11 6 16 2 21 8 2 1 2 7 9 12 4 17 25 22 7 2 3 5 8 7 13 1 18 11 23 4 0 4 0 5 9 4 14 5 19 56 24 5 23 5 83 10 13 15 0 20 10 25 Use to combine existing arrays as matrix elements 11 22 33 44 yy 2 0 5 0 2 0 5 0 yy 2 0000 2 0000 1 5000 1 5000 1 0000 1 0000 zz rand 2 4 rand 2 4 zz 0 9501 0 9501 0 2311 0 2311 6 0 8913 0 8913 0 7621 0 7621 A 2 4 A 17 Rectangular Matrix Scalar 1 by 1 array Vector m by 1 array 1 by n array Matrix m by n array Numerical Array Concatenation w 1 w 1 2 3 2 3 4 4 55 ww 66 77 88 99 xx 1 5 1 5 xx 5 10 14 Entering Numeric Arrays Scalar expansion Columns n 3 4 1 Rows m 3 00 00 00 23 0000 23 0000 2 4 1 2 10 5000 10 5000 bb 2 8000 2 8000 00 2 6458i 2 6458i 10 5000 10 5000 00 00 00 13 Entering and Generating Matrices Subscripts Scalar Expansion Concatenation Deleting Rows and Columns Array Extraction Matrix and Array Multiplication 11 33 22 44 Use square brackets cat a a cat a a 2 a 2 a 3 a 3 a 4 a 4 a 5 a 5 a 6 a 6 a cat a cat a 11 22 22 44 33 44 66 88 Column separator 33 66 44 88 4 a 99 12 12 16 space comma 12 12 16 55 10 6 12 10 6 12 15 20 18 24 15 20 18 24 Row separator semicolon 55 0 5000 0 5000 a 1 a 1 2 3 2 3 4 4 aa 00 0 4565 0 4565 0 0185 0 0185 16 Note The resulting matrix must be rectangular 2 Array Subscripting Indexing Deleting Rows and Columns A 1 A 1 55 9 4 9 4 33 2 5 2 5 0 1 0 1 10 10 3i 1 3i 1 AA 1 0000 1 0000 4 0000 4 0000 5 0000 5 0000 3 0000 3 0000 0 1000 0 1000 A 2 A 2 AA 10 0000 10 0000 1 0000 1 0000 4 0000 4 0000 9 0000 9 0000 2 5000 2 5000 1 9 0000 9 0000 2 5000 2 5000 A 1 0000 3 0000i 1 0000 3 0000i A 3 1 A 3 0 1000 1 0000 0 1000 1 0000 3 0000i 3 0000i A 2 2 A 2 2 Indexed empty matrix assignment Indexed empty matrix assignment is is not not allowed allowed 17 2 4 1 10 2 8 2 1 2 7 3 7 2 3 5 4 0 4 0 5 9 5 23 5 1 6 3 4 5 11 6 16 9 12 4 17 25 22 7 13 1 18 11 23 4 14 5 19 56 24 83 10 1315 0 20 10 25 8 1 2 21 A 1 5 5 A 1 end end A 5 A end A 21 25 A 21 end A 4 5 2 3 A 9 14 10 15 18 Matrix Manipulation Functions Matrix Multiplication aa 1 1 22 33 4 4 55 66 77 8 8 bb ones 4 3 ones 4 3 cc a b a b 2x4 4x3 zeros Create an array of all zeros ones Create an array of all ones eye Identity Matrix rand Uniformly distributed random numbers diag Diagonal matrices and diagonal of a matrix size Return array dimensions repmat Replicate and tile a matrix 2x4 4x3 2x3 cc 10 10 26 26 10 10 26 26 10 10 26 26 a 2nd row b 3rd column Array Multiplication aa 1 1 22 33 4 4 55 66 77 8 8 bb 1 4 1 4 1 4 1 4 cc a b a b cc 11 55 44 12 12 99 21 21 16 16 32 32 c 2 4 a 2 4 b 2 4 19 20 Matrix Manipulation Functions Elementary Math det Matrix determinant inv Matrix inverse eig Evaluate eigenvalues and eigenvectors rank Rank of matrix Logical Operators Math Functions Polynomial and Interpolation 21 25 3 Elementary Math Function Logical Operations equal to greater than less than Greater or equal less or equal not and or abs sign Absolute value and Signum Function sin cos asin acos Triangular functions exp log log10 Exponential Natural and Common base 10 logarithm ceil floor Round toward infinities fix Round toward zero Mass Mass 2 2 10 10 NaN NaN 30 30 11 11 Inf Inf 31 31 each pos each pos Mass 0 Mass 0 each pos each pos 00 11 …


View Full Document

Access the best Study Guides, Lecture Notes and Practice Exams

Loading Unlocking...
Login

Join to view MATLAB Tutorial and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view MATLAB Tutorial and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?