f I have a circle and i generated 50 random points inside , how can i assign unique id to every random point inside it , i want to have like user(1),us​er(2),....​.,user(50) ? so i can call any point inside the circle with this id

조회 수: 1 (최근 30일)
f I have a circle in matlab and i generated 50 random points inside , how can i assign unique id to every random point inside it , i want to have like user(1),user(2),.....,user(50) ? so i can call any point inside the circle with this id i have these two codes to make a circle and generate the random points inside it if I have a circle and i generated 50 random points inside , how can i assign unique id to every random point inside it , i want to have like user(1),user(2),.....,user(50) ? so i can call any point inside the circle with this id i have these two codes to make a circle and generate the random points iside it
%%// Plot the circle
x = linspace(-sqrt(10),sqrt(10));
y1 = sqrt(10-x.^2);
y2 = -sqrt(10-x.^2);
plot(x,y1,x,y2)
axis equal
%%// Choose from 1000 random point pairs
c=[0 0];
N = 1000;
%%// Radius of circle
radius = sqrt(10);
%%// Create a random point matrix Nx2
points_mat = [ radius*2*(rand(N,1)-0.5) radius*2*(rand(N,1)-0.5)];
%%// Select the first 50 pairs that lies inside circle
ind1 = find(sqrt( points_mat(:,1).^2 + points_mat(:,2).^2 )<radius); points_mat=points_mat(ind1(1:50),:);
%%// Plot the 50 points on the circle
hold on
text(0,0,' Center') %%// Center
text(points_mat(:,1),points_mat(:,2),'n') %%// 50 points
%// Set parameters
R = 15; %// radius
C = [0 0]; %// center [x y]
N = 50; %// number of points inside circle
%// generate circle boundary
t = linspace(0, 2*pi, 100);
x = R*cos(t) + C(1);
y = R*sin(t) + C(2);
%// generate random points inside it
th = 2*pi*rand(N,1);
r = R*rand(N,1);
xR = r.*cos(th) + C(1);
yR = r.*sin(th) + C(2); zR=[xR yR];
%// Plot everything
figure(1), clf, hold on
plot(x,y,'b') plot(C(1),C(2),'r.', 'MarkerSize', 60)
plot(xR,yR,'p')
axis equal

답변 (2개)

Image Analyst
Image Analyst 2014년 4월 2일
I don't understand. xR HAS a unique label for every point - it's the index! You don't need anything more. However if you want it as a separate row, then do
newX = [1:length(xR); xR];

Walter Roberson
Walter Roberson 2014년 4월 2일
Store the coordinates in a 2D matrix and use the row number, so user(5,:) for example.
Or use a cell array and use {} instead of (), so user{5} for example.

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by