How can I count the number of circles with particular radius and center which overlap, without a loop? (I need to speed it up)
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
The section of code below works to count how many times a particular grid point (with grid points much smaller than the circles themselves) is contained within a circle (i.e. how many circles overlap at each grid point) by making a mask for each individual circle and then adding the total to a matrix "cnts". My problem is that I need to do this for potentially hundreds of thousands of circles. Is there a way to speed up the masking/counting process without using the for loop (which I'm assuming is taking most of the time)? Thanks for any suggestions!
---------------------------------------------------------------------
%% loop over each circle to create a mask and count how many circles hit each grid point
cnts = zeros(size(xx));
for i = 1:length(xc)
xc = x_centers(i); % find the center point of circle #i
yc = y_centers(i);
mask = ((xx-xc).^2 + (yy-yc).^2)<(beam_diameter/2)^2; %create a mask for that circle
% add counts to a grid to determine how many circles hit each grid point
cnts = cnts+mask;
end
0 Commenti
Risposte (1)
Ganesh Regoti
il 17 Lug 2019
From your question, you need an alternative which works as for loop and more optimized. The concept of vectorization works well for your case.
You can refer more about vectorization here
Vedere anche
Categorie
Scopri di più su Contour Plots in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!