Presentation is loading. Please wait.

Presentation is loading. Please wait.

March 2005 1R. Smith - University of St Thomas - Minnesota Today’s Class Class StuffClass Stuff ProjectProject Vectors and DimensionsVectors and Dimensions.

Similar presentations


Presentation on theme: "March 2005 1R. Smith - University of St Thomas - Minnesota Today’s Class Class StuffClass Stuff ProjectProject Vectors and DimensionsVectors and Dimensions."— Presentation transcript:

1 March 2005 1R. Smith - University of St Thomas - Minnesota Today’s Class Class StuffClass Stuff ProjectProject Vectors and DimensionsVectors and Dimensions Scripts (shell scripts)Scripts (shell scripts) Import/Export of numerical matricesImport/Export of numerical matrices Working with parts of matricesWorking with parts of matrices

2 March 2005 2R. Smith - University of St Thomas - Minnesota Class Stuff Exam schedulesExam schedules –How many people need to switch exam days? Potential extra credit ‘quiz’Potential extra credit ‘quiz’ –Writing functions and such

3 March 2005 3R. Smith - University of St Thomas - Minnesota Project Project StorageProject Storage –I’ll set up shared space for each group project Multiple filesMultiple files –Use ‘zip’ if you have more than 3 files! Project PlanProject Plan –List of files/authors –List of functions in each file Identify each functionIdentify each function Explain what it doesExplain what it does –There should be enough to implement what your program needs to do!

4 March 2005 4R. Smith - University of St Thomas - Minnesota A Course Objective Writing functions and solving problems in both C and MatlabWriting functions and solving problems in both C and Matlab To do this, you must understand the features of each languageTo do this, you must understand the features of each language You should be able to write a simple function (with loops and conditionals) in both.You should be able to write a simple function (with loops and conditionals) in both.

5 March 2005 5R. Smith - University of St Thomas - Minnesota Vectors in Matlab Count 1 to size, not 0 to size-1Count 1 to size, not 0 to size-1 No “declaration” – just initialize and useNo “declaration” – just initialize and use –Easy to add and remove elements, NOT like C Square Brackets for the contentsSquare Brackets for the contents –elmstreet = [3 5 2 0 4 5 1] –No commas required –Curly braces & commas in C: int x[] = {1, 4, 2, 66, 5}; Parentheses for index valuesParentheses for index values –Like arguments to functions in Matlab or C –Square brackets in C for index values: name[i][0]

6 March 2005 6R. Smith - University of St Thomas - Minnesota Working with vectors Addressing: first element = 1Addressing: first element = 1 –Last element: “end” Addressing some elements: foo([1 2 5])Addressing some elements: foo([1 2 5]) Adding to a vector: foo = [foo, 2, 3]Adding to a vector: foo = [foo, 2, 3] –or: foo(end+1) = 3 –Fibonacci Removing: foo(2:3) = []Removing: foo(2:3) = [] Functions on vectorsFunctions on vectors –sum, mean, max, length –find -> list of indices of non-false (non 0) elements

7 March 2005 7R. Smith - University of St Thomas - Minnesota Boolean vectors Created with logical operatorsCreated with logical operators –x = foo > 3 –x contains 1s and 0s for elements of foo that are >3 –Can say foo(x) to create a vector of just those elements A ‘special’ kind of vectorA ‘special’ kind of vector Not just any vector of 1s and 0s.Not just any vector of 1s and 0s. Find functionFind function –Takes boolean vectors –Also takes any vector with 0s and non-0s logical functionlogical function –Converts vector of 0s and non 0s to a boolean vector

8 March 2005 8R. Smith - University of St Thomas - Minnesota Vectors versus Function Names Both C and Matlab are stupid about thisBoth C and Matlab are stupid about this –But each in their own way What happens in C?What happens in C? –Declare a function named ‘min’ –Declare a variable named ‘min’ What happens in Matlab?What happens in Matlab? –There is a function named ‘sqrt’ –What if there is a vector named ‘sqrt’ ? –Say, sqrt = [1 2 3 4 5] –sqrt (4) is 4!

9 March 2005 9R. Smith - University of St Thomas - Minnesota Some Vector Exercises Use colon to pick even valuesUse colon to pick even values Use modulus to pick even indicesUse modulus to pick even indices Partial index listsPartial index lists Negative Index listsNegative Index lists

10 March 2005 10R. Smith - University of St Thomas - Minnesota Scripts Just save a series of Matlab commands in a fileJust save a series of Matlab commands in a file Give it a.m suffixGive it a.m suffix Refer to it by name inside Matlab as a ‘command’Refer to it by name inside Matlab as a ‘command’ Use % as comment marker (like //)Use % as comment marker (like //) Functions are different – we’ll get to that laterFunctions are different – we’ll get to that later

11 March 2005 11R. Smith - University of St Thomas - Minnesota Import/Export of Matrices New population vectorNew population vector –Row 1 = #people in a house –Row 2-5 = four highest ages of people in a house Using Excel to type in a matrixUsing Excel to type in a matrix Using TextpadUsing Textpad Importing/ExportingImporting/Exporting –x = importdata(‘file.txt’); –x = csvread(‘file.csv’); –csvwrite(‘file2.csv’, x);

12 March 2005 12R. Smith - University of St Thomas - Minnesota Parts of Matrices Try town(:,1), town(1,:), town(2:end,:)Try town(:,1), town(1,:), town(2:end,:)

13 March 2005 13R. Smith - University of St Thomas - Minnesota Creative Commons License This work is licensed under the Creative Commons Attribution-Share Alike 3.0 United States License. To view a copy of this license, visit http://creativecommons.org/licenses/by- sa/3.0/us/ or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA.


Download ppt "March 2005 1R. Smith - University of St Thomas - Minnesota Today’s Class Class StuffClass Stuff ProjectProject Vectors and DimensionsVectors and Dimensions."

Similar presentations


Ads by Google