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

Please, solve according to matlab codes step by step. h. Create a matrix called

ID: 3601027 • Letter: P

Question

Please, solve according to matlab codes step by step.

h. Create a matrix called MA which has length(VA) rows and each row equals to HA by using “meshgrid”.

Create the following matrix 12 35 36 12 54 28 34 65 66 62 41 65 A-148 23 48 87 10 40 77 65 76 22 38 54 76 13 12 10 52 38 a. Find locations (i.e. row and column indices) of 10th, 16th and 24th elements of matrix A. (Hint: Use "floor" and "rem" built-in functions.) b. Find the element index of A(2,3), A(3,4) and A(5,5). c. Use "reshape" command to convert the 5 by 6 given matrix A to a 10 by 3 matrix. Assign the new matrix into a variable called B. In which order the elements were assigned into new matrix? Explain d. Find locations (i.e. row and column indices) of 10h 16h and 24h elements of matrix B. e. Find the element index of B(2,3), A(7,3) and A(5,3). f. Sort matrix A based on the third column in ascending order and descending orders by using the "sortrows" built-in function. g. Assign the first column of matrix A into a vector called VA and last row into a vector HA.

Explanation / Answer

// The following code will create the matrix

A = [12 35 36 12 54 28; 34 65 66 62 41 65; 48 23 48 87 10 40; 77 65 76 22 38 54; 76 13 12 10 52 38];

a) // Following a row major matrix representation we can use the below code

row_index = floor(location/6) + 1; // here location can be set to 10, 16, 24

col_index = rem(location,6); // here location can be set to 10, 16, 24

b) // Following a row major matrix representation we can use the below code

element_index = (row_index-1)*6 + col_index; // here set (row_index, col_index) = (2,3), (3,4), (5,5)

c) B = reshape(A, 10, 3);

Here reshape takes 3 arguments. The first is the name of the new matrix, the second is the number of rows in the new matrix, the third is the number of columns of the new matrix. It converts A to a new matrix B of desired dimensions as follows.

B =12 36 54

34 66 41
48 48 10
77 76 38
76 12 52
35 12 28
65 62 65
23 87 40
65 22 54
13 10 38

d) // Following a row major matrix representation we can use the below code

row_index = floor(location/3) + 1; // here location can be set to 10, 16, 24

col_index = rem(location,3); // here location can be set to 10, 16, 24