TRINITY CSCI 2323 - Introduction to MATLAB

Unformatted text preview:

1Introduction to Matlab9-7-20052Opening Discussion■Do you have any questions about the quiz?■What did we talk about last class?■Do you have any questions about the assignment?■Let's go ahead and submit your assignments.3Matlab Environment■Bring up Matlab and lets play a second in the environment.■Like other interactive language environments (BASIC, Scheme, SML, etc), you can define things in Matlab and give them names. You don't have to provide types. We use = for assignment.■You can overwrite the values and the new values can even be different types.■Matlab variables can be scalars, strings, arrays, or other types we'll see later on.4m-files■Collections of commands can be organized in m-files (you can put functions there too as we will see later).■We aren't going to play with m-files today, but all of the assignments and the project you turn in in Matlab will be in the form of m-files that I can load up.5Comments■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.6Arrays and Indexing■Arrays/matrices are fundamental to Matlab. The language name comes from Matrix Laboratory. It has grown to do more than that in time, but it still has strong roots to doing array/matrix manipulation.■You can make an array by putting values between [ and ].■You pull them out by providing indexes. In Matlab things are 1 indexed so the first element has index 1.■You can also index with an array and you get an array back with the designated elements.7Array 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?■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.8Array Math■Let's answer the extra credit from the quiz now. 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.9Standard Arrays■Matlab provides a number of helpful functions to make arrays.oneszeroseye – Identity matrixrand – Random elementsdiag – Only has diagonal elements10Array 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.11Sorting, 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.12Minute Essay■What do you think about the fact that you can do so much “looping” through arrays without ever writing a loop?■Assignment #2 is due on Friday. Do the reading, it will really


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?