Announcements Exam 2 Next Week!! Final Exam : Monday May 6th, 2:00 – 4:00 p.m. HH 002 Wednesday : Exam 2 Study Day HH 002 for Questions
Arrays Array – Set of Values with One Name MatLab Creation : arrayName = [ 1,3,5 ]; Vector – One Dimensional Array Matrix – Two Dimensional Array Element – One Member (Value) in an Array Offset or Subscript – location of an Element in and Array (in MatLab, starting with 1) Row Vector - “Row” of Values Column Vector - “Column” of Values
Array Element Addition/Subtraction >> rowV = [ 1, 3, 5 ] rowV = 1 3 5 >> rowV + 2 ans = 3 5 7 >> rowV - 5 -4 -2 0
Array Element Multiplication/Division >> rowV * 2 ans = 2 6 10 >> rowV / 2 0.5000 1.5000 2.5000
Array Element Exponentiation >> rowV^2 Error using ^ One argument must be a square matrix and the other must be a scalar. Use POWER (.^) for elementwise power. >> rowV.^2 ans = 1 9 25
Array to Array Operations >> rowV2 = [ 2, 4, 6] rowV2 = 2 4 6 >> rowV + rowV2 ans = 3 7 11 >> rowV - rowV2 -1 -1 -1
Array to Array Operations >> rowV * rowV2 Error using * Inner matrix dimensions must agree. >> rowV .* rowV2 ans = 2 12 30
Array Functions – max(), min() >> max(rowV) ans = 5 >> min(rowV) 1
Array Functions – length(), size() length() - Number of Elements in Vector size() - Returns a vector [NumRows, NumCols] >> length(rowV) ans = 3 >> size(rowV) 1 3
Array Functions – sum() >> sum(rowV) ans = 9 >> sum(rowV2) 12
Exam 2 Everything Through Quiz 2 if/then switch/case while loops for loops Functions function result = doThis(parameter1, parameter2) Arrays Creation Access Scalar Element to Element Operations Array to Array Operations max(), min(), length(), size(), sum()