I have written the code displayed below to calculate the maximum distance which is working perfectly. I want to modify the code for another task but facing some challenges. I will be grateful for any help and guidance please. This is what I want to do:
I want to calculate the distance from each center (xs,ys) to all points (a,b). Thus if center is (0,0) I need the distance from this center to all points in (a,b). I also want to create a matrix such that if the distance between a center to the various points is less than or equal to 2(<=2), it should write one in the matrix but if its greater than 2 it should write zero in the matrix. This process should happen from each of the centers (xs,ys) to all points in (a,b) for me to get a matrix with ones and zeros after calculating the distance from each center to all points . I am particularly interested in displaying the matrix with ones and zeros after each iteration. I will be very grateful for help to get this done please. Thank you for helping me. Below is my code which I want to modify to accomplish this task.
xs=[0 2.5 -2.5 2 -2.5 -3 -4 1.5 -1 3.7] #x-cordinates of center
ys=[0 0.3 0.25 -2.5 -2.25 1.5 -1.7 2 -3 -2]# y-cordinates of center
a=[-1, -1, 1.2, 1.2, 1.2, 0.8, 2.5, 2.5, -3, -3, -1.5, 3, 0.9, -3.7, 3.7, 3, 1.8, -1.8, -3.7, -3.7, 0.5, 2.5, -2.2, 3.5, 0.5 ] #x cordinate of the points
b=[0.2, 0.8, -0.85, 1.2, 0.5, -1.5, -1.3, 1.4, 1.5, -1.3, -0.8, -2.7, -2.4, 0.5, 0.8, 2.8, 2.4, -2.6, -2.6, 2.6, 1.5, -2.5, -3.3, -0.8, 3.1 ] #y cordinate of the points
r=[]
function distance(xs, ys, a, b)
r = Float64[]
for (i,xv) in enumerate(xs)
R = Float64[]
for (j, jv) in enumerate(a)
push!(R, ((xs[i]-a[j])^2 + (ys[i]-b[j])^2)^0.5)
end
if length(R) > 0
push!(r, maximum(R))
end
end
return r
end
r=distance(xs, ys, a, b)