Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

matlab 2) How would you use max to find the maximum value of the matrix AER xn,

ID: 3785622 • Letter: M

Question

matlab

2) How would you use max to find the maximum value of the matrix AER xn, and also the index, i.e., (i, j), which contains this value? Do this in two ways. a) Use max to calculate the maximum in each column and its index, and then use max again but on the vector of maximum values. Hint It is always good to have a specific example in front of you when trying to understand a new MATLAB function. If you are at all confused by this problem, use a matrix such as A round (1000*sin reshape (1:15, 3, 5))) -757 657 841 544 420 -1000 909 989 991 959 141 -279 650 412 537 Look at the output of 354 Chapter 3. Arrays in MATLAB m, iml max (A) and then at Cm2, im21 F max (m) b) Use max (A C:))" to find the index of the column vector which contains the maximum value, and then convert this vector index of AC:) back to the corresponding matrix index (i, j). As discussed in ection trou can use indogub if trou wish

Explanation / Answer

a)

% m is the vector with max values for each colum and im is vector with row index of max value for each column

[m,im] = max(A)

%m2 is the max value for vector m and im2 is the index of max value in m and also the column index for m2 in A

[m2,im2] = max(m)

% m2 is the max value and im(im2) is the row value for the max value in A

x = im(im2)

y = im2

b)

% M is max value in matrix A , I is the linear index according to row major arrangement (counting index row wise)

[M, I] = max(A(:))

% x is the row and y is the column value for max element M in A

[x,y] = ind2sub(size(A),I)