Question: Your task is to write a MATLAB function that enumerates the neighbors of a rectangle in an m n mesh of rectangles. Assume that the

Your task is to write a MATLAB function that enumerates the neighbors of a rectangle in an mn mesh of
rectangles. Assume that the rectangles are numbered starting at 1 in the upper left corner and
increasing from left to right and top to bottom as shown in the example.
Your function should be called getNeighbors. It should take exactly three input arguments in this
order: m,n, and r. Here m is the number of rows in the mesh, n is the number of columns, and r is the
rectangle whose neighbors must be identified. The function should return exactly one argument, an
array containing the numbers of the neighbors in increasing order. Write your code so that the array is
directly generated in the correct order; do not use the sort function. For example,
getNeighbors (4,6,14) should return the array [7891315192021].
Your program should validate the input arguments and return and empty array (i.e.,[]) if any of the
inputs are invalid. More specifically, your program must check that m and n are not less than 2,r is the
number of a rectangle that exists in the mesh, and all input values are integers. For example, the
following should return an empty array because there is no rectangle with number 100 for the given
mesh size: getNeighbors (4,6,100).
Test your function using the testGetNeighbors test stub.
 Your task is to write a MATLAB function that enumerates the

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!