130 likes | 260 Views
REVIEWSsssss. Creating arrays Referencing arrays Traversing arrays. Many ways to create arrays (that's BOTH vectors and matrices…). Arrays – Creating Them (review1). Methods to create arrays. _________________________________ _________________________________
E N D
REVIEWSsssss Creating arrays Referencing arrays Traversing arrays
Many ways to create arrays (that's BOTH vectors and matrices…) Arrays – Creating Them(review1)
Methods to create arrays • _________________________________ • _________________________________ • _________________________________ • _______________ _________________ ones(), zeros(), rand(), eye() … etc… • __________________________________ (using loops) • range operator (the colon : ) • upload data from a file (.txt, .xls…)
Review creating vectors • & 2. hardcoding vectors, or using variables v1 = [3, 5, 77, -54]; v2 = [ height, height, height +3, height-7]; v3 = [v1, v2]; • Using equations yvect = 2*xvect + 5./xvect + sind(xvect)
Review creating vectors • Using functions v1 = linspace(2,5.3, 34); using the rand() function: %a row vector with 5 floats between 0 to 5 excluded. v2 = ______________________ %a matrix with 4 rows, 2 columns of floats between 5 to 10 excluded. v3 = ______________________
Review creating vectors • Using the colon operator (addition pattern!) v1 = _____________________ v2 = _____________________
Reference vectors using a single index Reference matrices using 2 indices (or more) Referencing ARRAYS(review2)
Referencing vectors • For row vectors OR column vectors, use a single index. column vector row vector v(___) or use a variable: v(k)
Referencing matrices • For 2 dimensional (or more), use more than 1 index. • the row's number comes first • the column's number comes second • the next dimension after.. and so on m(____ , ___) m(____ , ___) or: m(_____ , _____) m or: m(_____ , _____)
Going through each element of the array, to analyze specifically Traversing arrays(Review3)
Traversing a vector using a loop • To traverse: "to go through" • To traverse a vector: to go through each element of the vector • opposite to: apply an equation to the entire vector in 1 step! • Traverse to find bumps in a curve • Traverse to calculate slope every 10 points • Traverse to count crossings of threshold (lab14)
Traversing using a _____ loop • Always use the ______ loop if you are to traverse an array for k = ___________________ %do stuff… end use the variable k as the index to reference each point within the vector the beginning k and end k are based off of what 'stuff' you're doing… for example
Traversing to approximate slope every 10 pts k+1 k for k = ___:10:__________________ %calculate slope slope = (y(k+1)-y(k-1))/(x(k+1)-x(k-1)); %show on plot %(code in future) end k-1 pt4 pt5 … k pt3 … pt2 pt1 length(y)