Download presentation
Presentation is loading. Please wait.
1
Announcements
2
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
3
Array Element Addition/Subtraction
>> rowV = [ 1, 3, 5 ] rowV = >> rowV + 2 ans = >> rowV - 5
4
Array Element Multiplication/Division
>> rowV * 2 ans = >> rowV / 2
5
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 =
6
Array to Array Operations
>> rowV2 = [ 2, 4, 6] rowV2 = >> rowV + rowV2 ans = >> rowV - rowV2
7
Array to Array Operations
>> rowV * rowV2 Error using * Inner matrix dimensions must agree. >> rowV .* rowV2 ans =
8
Array Functions – max(), min()
>> max(rowV) ans = 5 >> min(rowV) 1
9
Array Functions – length(), size()
length() - Number of Elements in Vector size() - Returns a vector [NumRows, NumCols] >> length(rowV) ans = 3 >> size(rowV)
10
Array Functions – sum()
>> sum(rowV) ans = 9 >> sum(rowV2) 12
11
Matrices Matrix – Two Dimensional Array MatLab Creation :
matrixName = [ 1,3,5;2,4,6 ]; Row – Horizontal Values Column – Vertical Values Element – One Member (Value) in an Array Offset or Subscript – For Matrix, given as Row, Column Pair (e.g., matrixName(1,2) )
12
Matrix Creation >> matrixOne = [1,2,3;3,4,5];
>> disp(matrixOne) >> rowV = [9, 10]; >> rowV2 = [11,12]; >> matrixTwo = [rowV;rowV2]; >> disp(matrixTwo)
13
Matrix Creatix (Cont) >> matrixThree = [matrixTwo; matrixTwo];
>> disp(matrixThree) >> matrixThree = [matrixTwo, matrixTwo];
14
Matrix Creation (Cont)
>> disp(matrixOne) >> disp(matrixTwo) >> matrixFour = [matrixOne;matrixTwo]; Error using vertcat Dimensions of matrices being concatenated are not consistent. >> matrixFour = [matrixOne,matrixTwo]; >> disp(matrixFour)
15
Matrix Addressing >> disp(matrixFour) 1 2 3 9 10 3 4 5 11 12
>> disp(matrixFour(1,1)) 1 >> disp(matrixFour(2,5)) 12 >> disp(matrixFour(-3,1)) Subscript indices must either be real positive integers or logicals. >> disp(matrixFour(1,1000)) Index exceeds matrix dimensions. >> matrixFour(1,7) = 1000;
16
Matrix Addressing (Cont)
Colon (:) means “all” or range >> disp(matrixFour) >> disp(matrixFour(:,4)) 9 11 >> disp(matrixFour(2,:))
17
Matrix Addressing (Cont)
>> disp(matrixFour) >> disp(matrixFour(:,2:5))
18
Matrix Scalar Operations
>> disp(matrixFour) >> disp(matrixFour + 2) >> disp(matrixFour * 2)
19
Matrix Transposition >> disp(matrixThree) 9 10 9 10 11 12 11 12
>> disp(matrixThree')
20
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()
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.