Slide 1Slide 2Slide 3Slide 4Slide 5Slide 6Slide 7Slide 8Slide 91Introduction to Matlab1/25/20082Opening Discussion■Do you have any questions about the assignment that is due today?■Let's go over how to turn it in.■What did we talk about last class?3Comments■Single line comments in Matlab begin with %. The rest of the line is a comment.■You can also make code blocks by enclosing the comment between %{ and %}.■You'll want to have these in your m-files to help explain things. You can put them in the interactive environment as well if you just like typing more.4Array Construction and Orientation■What are some different ways of making arrays in Matlab? How many ways can you make an array of numbers between 1 and 10?■logspace vs. linspace■Joining arrays.■Normally these arrays come out as row-arrays. All the values are in a single row. We can also take the transpose of them to get a column array. How do we take the transpose in Matlab?■Using semicolons or line feeds between elements in an explicit creation puts elements on the next row. All rows must have the same size.5Standard Arrays■Matlab provides a number of helpful functions to make arrays.oneszeroseye – Identity matrixrand – Random elementsdiag – Only has diagonal elements6Array Math■Let's write code that will do one iteration of the Serpenski's triangle. We want a matrix with the 3 points as 3 rows and a value for the current point. We want to move half way to one of the 3 points. This can use both scalar-array and array-array mathematics.■Scalars are “expanded” to work with arrays.■Remember to put a . before the array-array operations. Otherwise you get matrix operations which isn't what you want here.7Array Manipulation■Indexing into arrays is very powerful in Matlab. You can pull full rows and columns with :.■You can also change the shape of arrays with reshape.■You can't read out of bounds, but you can assign there and the array will grow.■Logical arrays allow more powerful selection mechanisms.8Sorting, Searching, and Size■The sort function sorts arrays.■The find function searches for things in them.■The size and length functions tell you how big they are.9Concluding Remarks■What do you think about the fact that you can do so much “looping” through arrays without ever writing a loop?■Quiz #1 will be on Monday. Remember that assignment #1 is due
View Full Document