NOTE: Add a comment to each section of your code to note

NOTE: Add a comment to each section of your code to note what part of each problem it was written to answer. Write all of the code to complete this problem in an executive function and several user defined functions. Make sure that all of your code is present in these scripts. Do not perform any calculations in the command window that are not recreated in your scripts.

Write an executive function and several user defined functions that will perform the following actions:

Prompt the user to input a single positive integer. Validate the input and prompt the user to re-enter until a positive integer is given.

Create a matrix using the following code:

mat = magic(n)

Where n is the positive integer input by the user. Note, this will create a matrix called mat that is n x n in size.

Create a new matrix called mat_update, where each element in mat_update is equal to the mean of the surrounding elements at the corresponding location in mat.

Example:

If user inputted 4, the result of magic(4) would be:

mat_update(1,1) would be the mean of the values adjacent to mat(1,1). Since mat(1,1) is on the corner, mat_update(1,1) = (5 + 2)/2 = 3.5

mat_update(1,2) would be the mean of the values adjacent to mat(1,2). Since mat(1,2) is on the edge, mat_update(1,2) = (16 + 11 + 3) / 3 = 10

mat_update(2,2) would be the mean of the values adjacent to mat(2,2). Since mat(2,2) is in the middle, mat_update(2,2) = (5 + 2 + 10 + 7) / 4 = 6

Following this pattern, the final result will be:

Once you have created mat_update, use the disp() command to display the matrix to the screen

Test Cases:

The post NOTE: Add a comment to each section of your code to note appeared first on PapersSpot.

CLAIM YOUR 30% OFF TODAY

X
Don`t copy text!
WeCreativez WhatsApp Support
Our customer support team is here to answer your questions. Ask us anything!
???? Hi, how can I help?