Computing for Engineers
Computing for Engineers CS 1371
Popular in Course
Popular in ComputerScienence
This 0 page Class Notes was uploaded by Alayna Veum on Monday November 2, 2015. The Class Notes belongs to CS 1371 at Georgia Institute of Technology - Main Campus taught by David Smith in Fall. Since its upload, it has received 8 views. For similar materials see /class/234168/cs-1371-georgia-institute-of-technology-main-campus in ComputerScienence at Georgia Institute of Technology - Main Campus.
Reviews for Computing for Engineers
Report this Material
What is Karma?
Karma is the currency of StudySoup.
Date Created: 11/02/15
Arrays Arrays vs Vectors All vectors are just 1 row arrays Arrays also homogenous collections gt Every value must be the same Arrays must always be rectangular gt You can never have a jagged array gt If you try to make one matlab will usually error or fill in zeros Creating Arrays Direct Access gt Use semi colons to separate rows Each row must be the same length Functions gt Linspace and colon can39t make arrays gt ones zeros rand can AccessingIndexing Emphasize index row then column Show indexing still done in parentheses but we separate each dimension by a comma gt arrr c v Single indexing gt Same rules apply must be positive integers in the range I arr2 7 I arr4 8 I row then column shorthand operators End I end is in relation to the position I arrend l end Wil be the value of the last row I arrl end end will be the value of the last column I arrend end is fine each end will just be the value for that dimensin I end makes no context outside of indexing If you want dimensions use size Colon z gt colon means all of that dimension I arrl first row all columns I arr l all rows first column I arr all rows all columns equivalent to just doing arr J Multiple ndices IMPORTANTIII gt Matlab returns the intersection of the rows you want and the columns you want I arrrows7want colsgwant I rowsiwant a vector of row indices I colsgwant a vector of col indices I The output array will be dimensions lengthrows7wantlengthcols7want I Example o arrl 3 5 2 4 9 Output is a 3x2 Q Will have the l 3 5 rows but only with the values at the columns 2 Setting positions gt Same as vectors except now specify rows and columns gt specify the spots you want to set on the left hand side want in those spots on the right hand side I IMPORTANT Spots you specify and the values you put in those spots must be same dimension or the value must be scalar and what you Deleting elem en t5 gt Can only delete rows or columns else the array will become jagged I arrl gt deletes first row I arr 3 gt deletes 3rd column I arr24 j gt deletest rows 2 and 4 gt ERRORS 39 arr3 2 1 I arr3 lzend I Must use to delete Linearized Indexing giving one position is not an error gt arr7 is ok When doing linear indexing the indices are found by counting down the columns To linearize an array to a column vector just do gt arr If you want that to be a row vector just transpose or gt arrlend When array is linearized it just goes down the columns Indexing with one specification always leads to a vector gt vecl35 gt vector gt arrl35 gt vector Slicing topbottom halves gt arrlend2 z arrend2lend quarters odd rowscolumns even rowscolumns Reversing rowscolumns Logical Indexing arrays The masking principle You are basically overlaying another arrayvector of trues and false and the only spotsthat come out is where there were trues To find the elements greater than 4 gt arrarr gt 4 gt No need to specify rows and columns with logicals gt arr gt 4 gives you a logical ARRAY that overlays on top of the original If you do b arrarr gt 4 output always a vector gt Since you are indexing with only one input it is like linear indexing If setting using logicals arrarr7condl arrarr7cond2 gt arrgcondl and arricond2 must have the same number of trues v Since linear indexing only important that the number of indices specified on each side is the same or gt arrarr4condl 5 gt Setting with scalar value on right the right is scalar v IMPORTANT Even though indexing with linear inputs the array on the left hand side maintains its dimensions gt It only linearizes it if it was on the right hand side of an equal sign Array Operators when to use vs gtn trix multiplication versus scalar multiplication gtthe same idea is true and A gt14ention the cases where it is ok to use either aka when one of the values is scalar v Transposing an array 39 gtan MxN array becomes an NxM gtShow how to transpose an array each row becomes a column in the new array Array Functions functions like sum mean go down the columns gtlf you want to go across rows you can either I sumA39 aka make the rows columns or I sumA v To get the overall of an array use the fact that the sum of the sum along the columns is just the overall sum sumsumarr gtn anmeanarr gt1ninminarr