Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Contemporary Issues In Database Design And Information Systems Development

Authors: Keng Siau

1st Edition

1599042894, 978-1599042893

More Books

Students also viewed these Databases questions

Question

Understand analog transmission of digital data

Answered: 1 week ago