CS 1371 Final Exam Review Notes

# CS 1371 Final Exam Review Notes - CS 1371 Final Exam Review...

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

CS 1371 Final Exam Review Notes Functions Function header o Function [quotient] = myDivide(in1, in2) Quotient and myDivide cannot be the same o Quotient = in1 ./ in2; o End mod(x,y) gives the remainder when x is divided by y Vectors = zero or more numbers collected together Vectors store only one type of data at a time ( logical OR double, not BOTH ) Row Vector: RowVec = [3 7 2 9] Column Vector: ColVec = [3; 7; 2; 9] or [3 7 2 9]’ Colon operator o Vec = start: step: end o If step size isn’t specified, default is 1. o b = 5:-1:2 [5 4 3 2 ] o c = 5:2 [ ] empty o d = 5:-1:7 [ ] empty Linspace o Linspace (start, end, amount of evenly spaced numbers) If the number of increments is not specified, default number would be 100 Zeros o Zeros (rows, columns) Concatenating vectors o If you try to concatenate vectors that are different in terms of dimensions, an error would occur. Example: o Vec = [27 32 53 47] o Vec2 = [1 2 3 4 5] o Vec3 = [Vec2, Vec] o Vec3 = [1 2 3 4 5 27 32 53 47] Adding o Vec4 = [2 4 6]; Vec5 = [1 2 3] o Vec6 = [Vec4 + Vec5] [3 6 9], adds element by element. o You can’t use “sum” because then that would add all the elements up together, not separately. o Vectors have to have the same length and shape in order to perform algebraic operations. o c = [5,6,7]+3 [8,9,10]

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

View Full Document
Length () o Examples: o z = linspace (1, 2) o x = length (z) o x = 100 because default for linspace is 100 o x = length(2:1) 0 o vec = [9 11 23 4] o vec(7) = vec(1) % indexing o vec = 9 11 23 4 0 0 9] o length(vec) = 7 Accessing / Indexing vectors o vec ( ) = … changes value of elements at specified positions o … = vec ( ) grabs specified elements and store them in variable o Can’t index with fractions or negative numbers. o Vec4 = [2 4 6 4] o Vec = Vec4([1, 3, 4]) 2 6 4 o You have to have the square brackets within the parentheses. vec ([vec of values]) o vec = 1:2:10 [1 3 5 7 9] o vec([1,end]) [1,9] Changing the elements within a vector: o Vec = [27 32 53 47] o Vec(2) = 73 Vec = [27 73 53 47] Changing multiple elements within a vector: o Vec4 = [2 4 6 4] o Vec4 ([1 3 4]) = 0 [0 4 0 0] To make disappear the elements within a vector: o Vec4 = [2 4 6 4] o Vec4 ([1 3 4]) = [ ] o [4] Example: o vec 2 = [10, 10, 11, 11, 20, 0, -1] o vec 2 = ([1,3]) = [20, 20] o vec [20, 10, 20, 11, 20, 0, -1] o Vector of unknown length and I want every element at an odd position
o oddNum = vec(1:2:end) o o Vector of unknown length and I want every element at an even position o evenNum = vec(2:2:end) Logicals and Indexing with logicals Data type that can take 2 values: true false == equal <= less or equal >= greater or equal < less > greater & (and) true if both inputs true I (or) true if at least one input is true ~ (not) true if input is false Output: 1 is a “true” and 0 is a “false” Vec4 = [2 4 6 4]; I want to find where the value 4s are. o

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 02/28/2012 for the course CS 1371 taught by Professor Stallworth during the Fall '08 term at Georgia Tech.

### Page1 / 36

CS 1371 Final Exam Review Notes - CS 1371 Final Exam Review...

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

View Full Document
Ask a homework question - tutors are online