TRINITY CSCI 2323 - Introduction to MATLAB

Unformatted text preview:

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.oneszeroseye – Identity matrixrand – Random elementsdiag – 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

TRINITY CSCI 2323 - Introduction to MATLAB

Documents in this Course
Load more
Download Introduction to MATLAB
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Introduction to MATLAB and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Introduction to MATLAB 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?