필터 지우기
필터 지우기

How to make a grid of dots?

조회 수: 8 (최근 30일)
Tyler Bodnarik
Tyler Bodnarik 2020년 10월 18일
댓글: Tyler Bodnarik 2020년 10월 18일
I have a function to plot a circle:
function circle = circleplot(x,y,r,c)
th = 0:pi/50:2*pi;
x_circle = r * cos(th) + x;
y_circle = r * sin(th) + y;
circle = plot(x_circle, y_circle);
hold on
fill(x_circle, y_circle, c);
plot(x, y, 'p', 'MarkerSize',15, 'MarkerFaceColor','r');
axis equal
hold off
end
I'd like to use this function to make a grid of dots that have circles with a radius of 1. Also, I want to have a certain amount of spacing between the center of each circle. Would I need to alter my function in any way or do I do all of this with inputs alone? Greatly appreciate any help/advice!
  댓글 수: 2
Tyler Bodnarik
Tyler Bodnarik 2020년 10월 18일
x = [-50:5:50];
y = [-50:5:50];
r = 1;
c = 'k';
figure(2)
for i = 1:21
circleplot(x(i),y(i),r,c)
end
xlim([-55 55])
ylim([-55 55])
I have this so far. The only issue is now only the last point (x=50 y=50) is being shown on the plot. I want each individual point of the graph. Should be 21 total. How could I do that?
Tyler Bodnarik
Tyler Bodnarik 2020년 10월 18일
update: I just needed the hold on/off commands.
x = [-50:5:50];
y = [-50:5:50];
r = 1;
c = 'k';
figure(2)
for i = 1:21
hold on
circleplot(x(i),y(i),r,c)
end
xlim([-55 55])
ylim([-55 55])
hold off

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by