Final+Exam+Review

# Final+Exam+Review - Vectors Conditionals and Itteration...

This preview shows pages 1–9. Sign up to view the full content.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Vectors Conditionals and Itteration Functions Strings Cell Arrays Structures and Structure Arrays Arrays File I/O Recursion Plotting Bodies of Rotation Matrices Images Numerical Methods Sound Sorting Queues (Graph Search)
We remember these right? Of course, you’ve been doing them all semester now! They contain only numerical values of class double. You can create them several ways, such as: 1. Colon Operator: x = 2:2:10; x = [2 4 6 8 10]; 2. Manually using square brackets : x = [1 2 3 4 5]; 3. Linspace: x = linspace(4, 20, 5) x = [4 8 12 16 20]; Remember linspace assumes 100 values if you do not specify in the third input parameter. 4. Concatenation: x = [A B C]; horizontally concatenates vectors A, B, and C.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Indexing/Assignment : If you want to index the 2 nd element in your vector: x = vec(2); If you have a vector, vec, and you want the third element to be a 4: vec(3) = 4; Or if you wish the 5 th and 6 th elements in your vector to be a 7 and an 8: vec([5 6]) = [7 8]; If you wish to remove the last 3 elements of the vector: vec(end-3:end) = [ ]; To get all even values from vec: new_vec = vec(mod(v1,2)==0) To get the values of all the even indices: new_vec=vec(2:2:end)
Remember ‘if’ and ‘switch’ statements? if’ Statements: if <condition> <code> elseif <condition> <code> else <code> end *do NOT forget the end!! Switch Cases: switch <variable> case {‘option1’, ‘option2’} <code> case ‘option’ <code> othewise <code> end

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
We would use an if statement to test multiple things at once. For instance if we have several variables that play into the coding decision we need to make: x needs to be larger than 5, y needs to be smaller than 7, and STR needs to be ‘hello world’ for us to add 6 to our vector, but if J is larger than 8 then we want to remove the last three letters from our string…. you see where this is going? Multiple variables are playing into the actions we are going to take. We use Switch if we are testing a single variable, say X, for certain conditions to carry out certain code. if we ‘switch x’ all of our cases are going to be wether ‘x’ is greater than, equal to, less than, true, false… ect.
For loops ! For loops are used to manipulate a vector or a variable with a known length. We can then set up an index something such as: for index = 1:length(variable) <code> end If you are deleting things from the variable as you loop through however, you’ll need to start from the end: for index = length(variable):-1:1 so that your index does not exceed the boundaries of the length of your variable, as it will be getting shorter each time.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
While Loops! While loops are a little more ambiguous and sometimes
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 11/21/2011 for the course CS 1371 taught by Professor Stallworth during the Fall '08 term at Georgia Institute of Technology.

### Page1 / 84

Final+Exam+Review - Vectors Conditionals and Itteration...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online