I need to write a Matlab function which finds the minimum distance between coord
ID: 3636117 • Letter: I
Question
I need to write a Matlab function which finds the minimum distance between coordinates. I have written a function for the maximum distance, but can not seem to get the minimum distance function to work. Here is the set up I have if you have any suggestions of where I am going wrong please let me know.function [min_dist] = minimumdistance
A = [2,5
3,10
15, 50
3,4];
min_dist = 0;
len = length(A);
for a = 1 : len - 1
xoff = A(a+1:len,1) - A(a,1);
yoff = A(a+1:len,2) - A(a,2);
sqr_dist = xoff.^2 + yoff.^2;
min_dist = min(min_dist,min(sqr_dist)) ;
end
min_dist = sqrt(min_dist);
end
Explanation / Answer
Hi, Your whole program is correct , just one logical mistake. See when u r searching for largest than initialise with smallest values like 0. But when u r searching for smallest , initialize min_dist = largest value like 9999. So change only min_dist = 9999;