I have written a code with the aim of getting a 25×10 Matrix at the final output but this doesnt seem to be working for me. I tried correcting this for the past days but I think I have a problem with my for loop. I kindly need help to get this done. I keep getting the error " BoundsError: attempt to access 25×10 Matrix{Float64} at index [2, 21] " but having a challenge correcting this. I need help please. Attached is the code please
a=[11.5, 13.4, 4.2, 39.9, 14.2, 17.1, 24.6, 30.8, 37.5, 12.7, 49.1, 27.3, 45.6, 3.4, 48.5, 48.5, 8.6, 11.2, 27.1, 29.4, 3.5, 29.1, 38.9, 13.4, 44.7]
b=[43.2, 42.6, 39.9, 38.4, 47.5, 22.0, 14.1, 18.3, 27.3, 26.3, 44.6, 14.1, 11.1, 30.8, 30.6, 19.0, 39.7, 34.9, 1.3, 9.3, 15.8, 6.8, 18.6, 17.2, 9.7]
n=10
m=25
r=10
len=50
using Random
Random.seed!(1235)
using Distributions
xs=rand(Uniform(1,len),n)
ys=rand(Uniform(1,len),n)
print(xs,ys)
function distance(xs, ys, a, b,n,m, r)
# n = length(xs)
# m = length(a)
coverage = zeros(m, n) # create the matrix and fill it with zeros
for i in 1:n
for j in 1:m
if sqrt( (xs[i]-a[j])^2 + (ys[i]-b[j])^2 ) <= r
coverage[i,j] = 1
@show i j coverage # display the matrix in each iteration
end
end
end
return coverage
end
coverage=distance(xs, ys, a, b,n,m,r)