Search for question
Question

Write a script saved using the format myscript student ID.m (e.g., myscript_1234567.m)

to solve the following problem.

(1) Create a 5x5 matrix of random integers between 4 and 40. Store the answer as variable C.

(2) Save a copy of C as variable D. Replace all diagonal and counterdiagonal elements of D

with 0.

(3) Create a submatrix of D by selecting the last 3 rows and last 3 columns. Store the answer

as variable E.

(4) List all the elements of E in row vector format and then arrange the elements in ascending

order. Select the non-zero elements of this vector as store the selection as variable F.

Display the output variables C, D, E and F clearly. Do not display anything else.

If you are unable to complete a section, type in the example matrix below and proceed to

next section. You can still receive full marks for any remaining sections.

Fig: 1