t site. The function should report the distance to that site as well (L). function [selected_site, L] = select_nearest_site(present_site, list_of_sites, x, y) Example: we have a list of four sites given to us: x = [2, 4, 1, 5] y = [3, 6, 5, 8] present_site = 4
Create a MATLAB function that can select the closest site from a list of other sites and also return the distance to that site. The function should report the distance to that site as well (L).
function [selected_site, L] = select_nearest_site(present_site, list_of_sites, x, y)
Example:
we have a list of four sites given to us:
- x = [2, 4, 1, 5]
- y = [3, 6, 5, 8]
present_site = 4
list_of_sites = [1, 2, 3] (Note: this essentially means, find me which of the 1st, 2nd, and 3rd site is closest to the present_site (4) where you use information about their positions stored in x and y)
L = distance
Example of use:
- x = [2, 4, 1, 5]
- y = [3, 6, 5, 8]
- present_site = 4
- list_of_sites = [1, 2, 3]
[selected_site, L] = select_nearest_site(4, [1 2 3], x, y)
ans:
selected_site
= 1
L
= 1.732
I've just included down below the function that I used to calculate the distances, that should be used to find L. This function calculates the distances from the point (x_c, y_c) - are the chosen points; to all the points provided by the
x_c and y_c is the chosen point.
- given location (2, -1) - this is x_c and y_c
- x = [0, 2, 3]
- y = [3, 2, 4]
Step by step
Solved in 3 steps with 2 images