Info

This question is closed. Reopen it to edit or answer.

Hi, I am trying to develop an algorithm that will plot random disc(circles) in square axis and then find the probality of isolated circles, i.e circle(s). Although the code worked but I am unsure its right if you look at the probability.

1 view (last 30 days)
r = 0.05;
a = 1-r;
b = r;
nc = 50;
x = (a-b) .*rand(nc,1) + b;
y = (a-b) .*rand(nc,1) + b;
centers = [x y];
radii = r.*ones(length(x),1);
%clear the axis
cla
%fix the axis limits
xlim([0 1])
ylim([0 1])
%set the axis aspect ratio to 1:1
axis square
box on
%display the circles
viscircles(centers,radii, 'EdgeColor','k');
D = pdist(centers);
K = D(:);% columnized
p = length(K);
count = zeros(p,1);
for i = 1:p
if K(i) <= 2*r
count(p) = count(p) + 1;
end
end
Prob = sum(count)/p

Answers (0)

This question is closed.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!