How to plot an NxN array of circles?
6 ビュー (過去 30 日間)
古いコメントを表示
I want to plot an NxN array of circles. Just to visualize, I attached an image of what I want to achieve. I'm new in MatlLab so I tried to plot a single circle first, and here is my code below:
n = 2^10; % size of mask M = zeros(n); I = 1:n; x = I - n/2; % mask x - coordinates y = n/2 - I; % mask y - coordinates [X,Y] = meshgrid(x,y); % create 2-D mask grid R = 200; % aperture radius A = (X.^2 + Y.^2 <= R^2); % Circular aperture of radius R M(A) = 1; % set mask elements inside aperture to 1 imagesc(M) % plot mask axis image
I really don't have any idea on how to plot a 2D-array of circles. The distance between two circles is two radii. I need this for my research. Hoping anyone can help.
0 件のコメント
採用された回答
Geoff Hayes
2018 年 2 月 11 日
Viron - you could just create one circle within a 2-D array whose number of rows and columns are identical to the diameter of your circle. For example, using code similar to yours
r = 50;
n = 1000;
X = repmat(linspace(-r,r,n), n, 1);
Y = rot90(X);
C = X.^2 + Y.^2 <= r^2;
imagesc(C)
axis image
The radius r for our circle is 50. We use linspace to create a row array of n elements from -r to r (so the interval [-50,50]). We then use repmat to repeat this row n times. We then rotate this matrix by 90 degrees counter-clockwise to get the Y (this should be identical to your use of meshgrid). We then create one circle as you have already done with the only difference being that the circle of radius 50 is now inside a square with the a length and width being the diameter of your circle.
We can then again use repmat to repeat the C to how many circles we want in the x and y direction.
nc = 10;
MC = repmat(C, nc, nc); % multiple circles
imagesc(MC)
axis image
3 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Surface and Mesh Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!