1 / 13

REVIEWSsssss

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. _________________________________ _________________________________

ross
Download Presentation

REVIEWSsssss

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. REVIEWSsssss Creating arrays Referencing arrays Traversing arrays

  2. Many ways to create arrays (that's BOTH vectors and matrices…) Arrays – Creating Them(review1)

  3. Methods to create arrays • _________________________________ • _________________________________ • _________________________________ • _______________  _________________ ones(), zeros(), rand(), eye() … etc… • __________________________________ (using loops) • range operator (the colon : ) • upload data from a file (.txt, .xls…)

  4. 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)

  5. 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 = ______________________

  6. Review creating vectors • Using the colon operator (addition pattern!) v1 = _____________________ v2 = _____________________

  7. Reference vectors using a single index Reference matrices using 2 indices (or more) Referencing ARRAYS(review2)

  8. Referencing vectors • For row vectors OR column vectors, use a single index. column vector row vector v(___) or use a variable: v(k)

  9. 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(_____ , _____)

  10. Going through each element of the array, to analyze specifically Traversing arrays(Review3)

  11. 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)

  12. 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

  13. 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)

More Related