필터 지우기
필터 지우기

How do I plot individual circles whose centers are points on a graph?

조회 수: 2 (최근 30일)
I generated some random numbers which represent random forces acting on a spring, I then divided this random forces by a spring constant 20.5 to get the random positions (using Hooke's Law), I selected the random positions between -50 and 50. This random positions were then plotted (using the code below);
x_max=50.0;
x_min=-50.0;
N = 100;
RandFor = 1030*rand(N,1) .* sign(randn(N,1));
k= 20.5;
x=RandFor./k;
x(x_min > x | x > x_max) = 0;
scatter( 1:length(x), x, 75,[0 0 0],'filled' )
plot(x)
figure(1)
%subplot(1,3,1:2)
xlabel('frames');
ylabel('Random Positions');
I need to plot individual circles centered on each plotted random position, thus for above code there should be 100 circles. These circles are one dimensional because the random positions are plotted only on the y-axis. so the circles have only y co-ordinates, the x-axis represents the captured frame of each circle.
I tried using the code below to plot the circle
function circle(a,b,r)
%x and y are the coordinates of the center of the circle
%r is the radius of the circle
%0.01 is the angle step,
ang=0:0.01:2*pi;
xp=r*cos(ang);
yp=r*sin(ang);
plot(a+xp,b+yp);
hold on;
end
But I don't know how to make the circle appear on each random position.

채택된 답변

Walter Roberson
Walter Roberson 2013년 1월 18일
You can use scatter() to plot circles. The third parameter to scatter() is the size of the circle.
  댓글 수: 9
Walter Roberson
Walter Roberson 2013년 1월 24일
Consider circle #17 (for example.) In frame #2, should only the new position of circle #17 be shown, or should both the old and new positions be shown?
If you want the positions to accumulate on the same graph, then just ensure you have done
hold on
after doing the first scatter().
EngStudent
EngStudent 2013년 1월 24일
I want the new position on frame #2, thus I want each circle to have its own frames, I will then develop a program to track the positions of the circle in each frame, these tracked positions will then be compared with the generated positons

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

추가 답변 (1개)

disha
disha 2013년 4월 5일
You can try the following modification in your code. plot(x,y,'--rs','LineWidth',2,... 'MarkerEdgeColor','k',... 'MarkerFaceColor','g',... 'MarkerSize',10) Hope this helps.

카테고리

Help CenterFile Exchange에서 Scatter Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by