ENG 06 – Lecture 3 notes

3 Pages
Unlock Document

University of California - Davis

ENG 06 – Lecture #3; 1/15/2013 Arrays  Very important; “the backbone” of MATLAB Arrays and Matrices  Matrix: a grid/array of numbers, w/ rows and columns  Refers to number of rows, then number of columns o Ex. 2x4 array has 2 rows and 4 columns  Arrays: Vectors (1D Matrix) o Only 1 row or 1 column o Row vector: enclose a list of elements in square brackets  Ex. x = [1 5 8 9]  Gives a 1 row and 4 columns o Column vector: tell MATLAB to skip to next row using semicolon  Ex. y = [1;5;8;9]  Gives a 4 row, 1 column array  Matrix o Z = [1 2 3;4 5 6] o 2x3 matrix (2 rows by 3 columns)  Transpose (perform operation using apostrophe ‘ ) o Switches rows and columns st st nd nd o 1 row becomes 1 column, 2 row becomes 2 column, etc. o diagonal does not change for square matrices Ways to Create Arrays  Generating Arrays: Colon o Use colon to create a vector x:y “from x to y”  Ex. a = 1:1000 o By default, colon uses steps of 1 o Add a number in the middle, x:z:y, to go from x to y with step size z o Ex. a = 1:0.1:1000 gives a vector containing [1 1.1 1.2…999.8 999.9 1000]  Generating Arrays: Linspace/Logspace o Linspace operator: spaces points evenly between a start number and end number  Variable = linspace(start,stop,# of points)  Ex. c = linspace(5,22,200) o Logspace operator: spaces points logarithmically between a start and end number o Both operators determine step size for you  Variable = logspace(start,stop,# of points)  Generating Arrays from Other Arrays o Other vertices/matrices can be included in brackets when creating an array o Ex. c = [1 2 3]; a = [c;c] o Creates matrix with 2 rows and 3 columns, each row is vector c o Concatenation (linking matrices) works as long as dimensions are compatible  Generating Arrays: Ones, Zeros, Eyes o ones(n) gives nxn matrix with 1s as entries o ones(n,m) gives nxm matrix with 1s as entries o zeros(n) gives nxn matrix with 0s as entries o zeros(nxm) gives nxm matrix with 0s as entries o eye(n) gives nxn identity matrix o eye(nxm) gives nxm matrix with a diagonal of 1s starting in the first row and ending at the last row; remaining columns have 0s  Generating Arrays: rand o rand(n) returns n x n matrix with pseudorandom values in the interval (0,1) o rand(n,m) gives n x m matrix o to create random matrix with integers between 0 and 10:  >>ceil(10*rand(3,3))  creates a 3x3 matrix with random values that are multiplied by 10 then rounded towards infinity (ceil function)  Using Array Editor to See and Access Values o Double click on variable that defines your vector/matrix in workspace o Brings up a spreadsheet with values o Use wi
More Less

Related notes for ENG 6

Log In


Don't have an account?

Join OneClass

Access over 10 million pages of study
documents for 1.3 million courses.

Sign up

Join to view


By registering, I agree to the Terms and Privacy Policies
Already have an account?
Just a few more details

So we can recommend you notes for your school.

Reset Password

Please enter below the email address you registered with and we will send you a link to reset your password.

Add your courses

Get notes from the top students in your class.