Download presentation
Presentation is loading. Please wait.
1
Array and Matrix Functions
EE 201 Fall 2013
2
Class Learning Objectives
Achieve Comprehension LOL of Array and Matrix Functions . C Spring 2012
3
Array Functions I=find(V)
returns the linear indices corresponding to the nonzero entries of the array V. C Spring 2012
4
Example: C Spring 2012
5
Example C Spring 2012
6
Array Functions length(A)
Computes either the number of elements of A if A is a vector or the largest value of m or n if A is an m × n matrix. length(A) C Spring 2012
7
Example C Spring 2012
8
Array Functions max(A)
Returns the algebraically largest element in A if A is a vector. Returns a row vector containing the largest elements in each column if A is a matrix. C Spring 2012
9
Array Functions min(A)
Returns the algebraically smallest element in A if A is a vector. Returns a row vector containing the smallest elements in each column if A is a matrix. . min(A) C Spring 2012
10
Array Functions size(A) sort(A) sum(A)
Returns a row vector [m n] containing the sizes of the m x n array A. size(A) Sorts each column of the array A in ascending order and returns an array the same size as A. sort(A) Sums the elements in each column of the array A and returns a row vector containing the sums. sum(A) C Spring 2012
11
For example, if A= -max(A) [6,2] -min(A) [-10,-5] -length(A) 3
-size(A) [3,2] -length(A) -sort (A) -sum(A) C Spring 2012
12
Sometimes we want to initialize a matrix to have all zero elements
Sometimes we want to initialize a matrix to have all zero elements. The zeros command creates a matrix of all zeros. Typing zeros(n) creates an n × n matrix of zeros, whereas typing zeros(m,n) creates an m × n matrix of zeros. Typing zeros(size(A)) creates a matrix of all zeros having the same dimension as the matrix A. This type of matrix can be useful for applications in which we do not know the required dimension ahead of time. The syntax of the ones command is the same, except that it creates arrays filled with ones. C Spring 2012
13
Generating Vectors from functions
zeros(m,n) mxn matrix of zeros ones(m,n) mxn matrix of ones x = zeros(1,3) x = x = ones(1,3)
14
Example: C Spring 2012
15
The identity matrix is a square matrix whose diagonal elements are all equal to one, with the remaining elements equal to zero. For example, the 4 × 4 identity matrix is I= The functions eye(n) and eye(size(A)) create an n × n identity matrix and an identity matrix the same size as the matrix A. C Spring 2012
16
Example: C Spring 2012
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.