Introduction to MATLAB - Temple Universitytug52596/AnaFiles/matlab_intro.pdf · Introduction to...
Transcript of Introduction to MATLAB - Temple Universitytug52596/AnaFiles/matlab_intro.pdf · Introduction to...
![Page 1: Introduction to MATLAB - Temple Universitytug52596/AnaFiles/matlab_intro.pdf · Introduction to MATLAB Computational Probability and Statistics 8/30/2017 (Temple University) Introduction](https://reader031.fdocuments.us/reader031/viewer/2022021821/5b144a2f7f8b9a397c8c4b97/html5/thumbnails/1.jpg)
Introduction to MATLABComputational Probability and Statistics
8/30/2017
(Temple University) Introduction to MATLAB 8/30/2017 1 / 15
![Page 2: Introduction to MATLAB - Temple Universitytug52596/AnaFiles/matlab_intro.pdf · Introduction to MATLAB Computational Probability and Statistics 8/30/2017 (Temple University) Introduction](https://reader031.fdocuments.us/reader031/viewer/2022021821/5b144a2f7f8b9a397c8c4b97/html5/thumbnails/2.jpg)
Course and labs web page
Course web page (Dr Pei Wang’s students):cis-linux1.temple.edu/~wangp/2033-PL/2033-index.htm
Labs web page:astro.temple.edu/~tug52596/cis2033fall2017
(Temple University) Introduction to MATLAB 8/30/2017 2 / 15
![Page 3: Introduction to MATLAB - Temple Universitytug52596/AnaFiles/matlab_intro.pdf · Introduction to MATLAB Computational Probability and Statistics 8/30/2017 (Temple University) Introduction](https://reader031.fdocuments.us/reader031/viewer/2022021821/5b144a2f7f8b9a397c8c4b97/html5/thumbnails/3.jpg)
MATLAB licence at Temple
All Temple University in-campus computers have student-versionMATLAB installed.
Temple University also provides student licenses:download.temple.edu
(Temple University) Introduction to MATLAB 8/30/2017 3 / 15
![Page 4: Introduction to MATLAB - Temple Universitytug52596/AnaFiles/matlab_intro.pdf · Introduction to MATLAB Computational Probability and Statistics 8/30/2017 (Temple University) Introduction](https://reader031.fdocuments.us/reader031/viewer/2022021821/5b144a2f7f8b9a397c8c4b97/html5/thumbnails/4.jpg)
About MATLAB
MATLAB (MATrix LABoratory) can be used for:
Numerical Computation (Technical computing)VisualizationApplication Development
Everything is represented as a matrix.
(Temple University) Introduction to MATLAB 8/30/2017 4 / 15
![Page 5: Introduction to MATLAB - Temple Universitytug52596/AnaFiles/matlab_intro.pdf · Introduction to MATLAB Computational Probability and Statistics 8/30/2017 (Temple University) Introduction](https://reader031.fdocuments.us/reader031/viewer/2022021821/5b144a2f7f8b9a397c8c4b97/html5/thumbnails/5.jpg)
(Temple University) Introduction to MATLAB 8/30/2017 5 / 15
![Page 6: Introduction to MATLAB - Temple Universitytug52596/AnaFiles/matlab_intro.pdf · Introduction to MATLAB Computational Probability and Statistics 8/30/2017 (Temple University) Introduction](https://reader031.fdocuments.us/reader031/viewer/2022021821/5b144a2f7f8b9a397c8c4b97/html5/thumbnails/6.jpg)
Built-in variables and constants
(Temple University) Introduction to MATLAB 8/30/2017 6 / 15
![Page 7: Introduction to MATLAB - Temple Universitytug52596/AnaFiles/matlab_intro.pdf · Introduction to MATLAB Computational Probability and Statistics 8/30/2017 (Temple University) Introduction](https://reader031.fdocuments.us/reader031/viewer/2022021821/5b144a2f7f8b9a397c8c4b97/html5/thumbnails/7.jpg)
Numeric Types
Matlab provides wide range of numerical and floating point types such as:
double,int (8,16,32 and 64 bits),uint ( 8,16,32,64 bits).
(Temple University) Introduction to MATLAB 8/30/2017 7 / 15
![Page 8: Introduction to MATLAB - Temple Universitytug52596/AnaFiles/matlab_intro.pdf · Introduction to MATLAB Computational Probability and Statistics 8/30/2017 (Temple University) Introduction](https://reader031.fdocuments.us/reader031/viewer/2022021821/5b144a2f7f8b9a397c8c4b97/html5/thumbnails/8.jpg)
Elementary math functions
(Temple University) Introduction to MATLAB 8/30/2017 8 / 15
![Page 9: Introduction to MATLAB - Temple Universitytug52596/AnaFiles/matlab_intro.pdf · Introduction to MATLAB Computational Probability and Statistics 8/30/2017 (Temple University) Introduction](https://reader031.fdocuments.us/reader031/viewer/2022021821/5b144a2f7f8b9a397c8c4b97/html5/thumbnails/9.jpg)
Matrices and vectors
To enter a matrix:2 5 36 4 1typeA = [2, 5, 3; 6, 4, 1].
Another way to specify a row:B = [1:1.5:6; 2 3 4 5].
Add elements to a matrix:D =[]; D=[D;5]; D=[D;6;7]
Pre-defined matrices:E = zeros(4, 5)
(Temple University) Introduction to MATLAB 8/30/2017 9 / 15
![Page 10: Introduction to MATLAB - Temple Universitytug52596/AnaFiles/matlab_intro.pdf · Introduction to MATLAB Computational Probability and Statistics 8/30/2017 (Temple University) Introduction](https://reader031.fdocuments.us/reader031/viewer/2022021821/5b144a2f7f8b9a397c8c4b97/html5/thumbnails/10.jpg)
Basic matrix operations:
Addition:C = A + B
Subtraction:D = A - B
Multiplication:E = A * B (Matrix multiplication)E = A .* B (Element wise multiplication, A and B same size)
Division:Left Division and Right DivisionF = A . / B (Element wise division)F = A / B = A*inv(B) (A * inverse of B)F = A .\B (Element wise division)F = A\B=inv(A)*B (inverse of A * B)
(Temple University) Introduction to MATLAB 8/30/2017 10 / 15
![Page 11: Introduction to MATLAB - Temple Universitytug52596/AnaFiles/matlab_intro.pdf · Introduction to MATLAB Computational Probability and Statistics 8/30/2017 (Temple University) Introduction](https://reader031.fdocuments.us/reader031/viewer/2022021821/5b144a2f7f8b9a397c8c4b97/html5/thumbnails/11.jpg)
Matrix functions
(Temple University) Introduction to MATLAB 8/30/2017 11 / 15
![Page 12: Introduction to MATLAB - Temple Universitytug52596/AnaFiles/matlab_intro.pdf · Introduction to MATLAB Computational Probability and Statistics 8/30/2017 (Temple University) Introduction](https://reader031.fdocuments.us/reader031/viewer/2022021821/5b144a2f7f8b9a397c8c4b97/html5/thumbnails/12.jpg)
Functions that return matrices
Matrix with ZEROS:A = zeros(m, n)
Matrix with ONES:B = ones(m, n)
IDENTITY Matrix:I = eye(m, n)
RANDOM Matrix:I = rand(m, n)
m - rows,
n - columns.
(Temple University) Introduction to MATLAB 8/30/2017 12 / 15
![Page 13: Introduction to MATLAB - Temple Universitytug52596/AnaFiles/matlab_intro.pdf · Introduction to MATLAB Computational Probability and Statistics 8/30/2017 (Temple University) Introduction](https://reader031.fdocuments.us/reader031/viewer/2022021821/5b144a2f7f8b9a397c8c4b97/html5/thumbnails/13.jpg)
Array indexing, obtaining information
Size(A): returns [m n]
Length(A): returns max(size(A))
B = A(2:4,3:5) - B is a subset of A, containing rows 2 to 4 andcolumns 3 to 5.
D = A(:, [1,15,20]) - all rows, specified colums of matrix A
A(:, 2)=[] - delete second column.
(Temple University) Introduction to MATLAB 8/30/2017 13 / 15
![Page 14: Introduction to MATLAB - Temple Universitytug52596/AnaFiles/matlab_intro.pdf · Introduction to MATLAB Computational Probability and Statistics 8/30/2017 (Temple University) Introduction](https://reader031.fdocuments.us/reader031/viewer/2022021821/5b144a2f7f8b9a397c8c4b97/html5/thumbnails/14.jpg)
Characters and Strings
A = ’Alice’ - single quotes
use two single quotes within the definition if the text includes a singlequote
Concatenation: A = [’Alice’, ’followed’, ’the’, ’rabbit.’]
Convert numeric values to strings
num2str ,int2str .
(Temple University) Introduction to MATLAB 8/30/2017 14 / 15
![Page 15: Introduction to MATLAB - Temple Universitytug52596/AnaFiles/matlab_intro.pdf · Introduction to MATLAB Computational Probability and Statistics 8/30/2017 (Temple University) Introduction](https://reader031.fdocuments.us/reader031/viewer/2022021821/5b144a2f7f8b9a397c8c4b97/html5/thumbnails/15.jpg)
Control Flow
(Temple University) Introduction to MATLAB 8/30/2017 15 / 15