Plotting random points on a circle

조회 수: 5 (최근 30일)
ReturnToCastle
ReturnToCastle 2020년 5월 5일
댓글: ReturnToCastle 2020년 5월 5일
I am trying to plot 50 random points on a circle with a radius of 500 then store the x, y coordinates of the points in a matrix and calculate each point's distance from the centre of the circle (0,0), any reference I could use or how I can achieve this?

채택된 답변

TADA
TADA 2020년 5월 5일
Assuming you mean inside the circle and not on that circle, because then obviously the distance is 500 Anyway, it is much easier to work in polar coordinates for this task, then the distance is simply the radius we randomize
r = rand(1, 50) * 500;
theta = rand(1, 50) * 2 * pi;
[x,y] = pol2cart(theta, r);
plot(x,y,'o');
  댓글 수: 1
ReturnToCastle
ReturnToCastle 2020년 5월 5일
Yes, I meant inside the circle sorry, I hope your answer helps, thank you!

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

추가 답변 (1개)

David Hill
David Hill 2020년 5월 5일
a=2*pi*rand(1,50);
b=500*rand(1,50);
m=[b.*sin(a);b.*cos(a)];

카테고리

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

태그

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by