# Using viscircles to draw circles around points.

52 views (last 30 days)
Vance Blake on 23 Aug 2019
Hello, I am trying to draw to circles using viscircles but some of the circles end up in random space instead of around the center coordiantes ive given them. Below is the code I am using to draw my circles and a picture of what is happening on the plot. Any help would be greatly appreciated
% draw exlcusion range circles b/w hormone seeds and hormone seeds
HS_kept_x = HS_kept(:, 1);
HS_kept_y = HS_kept(:, 2);
LengthHS_kept = length(HS_kept);
hold on
for i = 1:n
centers_node5 = [x(i), y(i)];
elim_circles3(i) = viscircles(centers_node5, radii_node2, 'color', 'k', 'linestyle', '--');
end
for j = 1:LengthHS_kept
centers_HS_kept = [HS_kept_x(j), HS_kept_y(j)];
elim_circles4(j) = viscircles(centers_HS_kept, radii_node2, 'color', 'k', 'linestyle', '--');
end Vance Blake on 27 Aug 2019
alright so i tried reworking the code but for some reason it is still treating elim dist 2 as 10x10 i think it has something to do with this elim_dist2(j,i) = elim_dist2(i,j); Here is how i rewrote the code. Would it be better off just replacing the for loops with the code you suggested earlier ??
elim_dist2 = nan(numel(x)); % this to have nans on the diagonal after distance calculation
VN_HS_threshold = 16;
for i = SB:-1:1 % looping from largest index lets us avoid calculating the size of the elim_dist2 matrix without pying the price of dynamic growing of a matrix
for j = (i-2):-1:1 % distance symmetric (l(i1,i2) == l(i2,i1)) so calculate it once
elim_dist2(i,j) = sqrt((keep_x(i)-vn_x(j)).^2 + (keep_y(i)-vn_y(j)).^2);
elim_dist2(j,i) = elim_dist2(i,j);
end
end
% find the points that have its nearest neighbour further away than VN_HS_threshold:
i2keepVN_HS = find(min(elim_dist2)> VN_HS_threshold);
% put those into one pair of arrays
keep_x2 = keep_x(i2keepVN_HS);
keep_y2 = keep_y(i2keepVN_HS);
% and the others into another pair of arrays
x_close_neighbours2 = keep_x;
y_close_neighbours2 = keep_y;
x_close_neighbours2(i2keepVN_HS) = [];
y_close_neighbours2(i2keepVN_HS) = [];
E = [keep_x2, keep_y2];
HS_kept = E;
Vance Blake on 28 Aug 2019
Hey Adam I figured it out it was this line "[elim_dist2 = nan(numel(x))]" causing the problems because it sets up a NaN matrix based on the size of x whcih has 10 elements instead of the size i need for my second elimination. Took me a bit to see it but I went line by line running each piece of code individually like you suggested and figured it out. Thanks for putting up with my ignorance and all your help with my problems. make this an answer so that i can accpet it and give you the credit you deserve.
Adam Danz on 28 Aug 2019
Going line-by-line is often the best way to troubleshoot code and to really understand what's happening in the code. Well done!

Adam Danz on 28 Aug 2019
Summary of the discussion in the comment section under the question:
A matrix was pre allocated incorrectly which led to indexing problems.