Can we assign or associate the random points only that located inside the a specific range ?

조회 수: 1 (최근 30일)
Is there a way to assign the RED points which are located within the STARS range (assume STARS have range (as circle) is 100m raduis), while the RED points that are located out of the STAR range let them associated to the ''BLACK + which is range the outer circle that has raduis 1000m'' ?
ro=1000; % radius of the layout circle
NumBSs=10; % Number of Base stations
NumUEs=50; %Number of users
center=[0 0]; % center of the circle
theta_BSs=2*pi*(rand(NumPoints,1)); % distributed random number of Base stations
g = 0.5 * ro + 0.5 * ro * rand(NumBSs,1);
PosBSs_x=center(1)+g.*cos(theta_BSs);
PosBSs_y=center(2)+g.*sin(theta_BSs);
theta1 = rand(NumUEs, 1) * 2*pi; % distributed random number of Users
r1 = ro * sqrt(rand(NumUEs, 1));
PosUE = [r1 .* cos(theta1(:)) + center(1),r1 .* sin(theta1(:)) + center(2)];
% Initial plot objects
hfig = figure('Color', 'w');
hax=axes('parent',hfig);
% Plot of deploying points
hdots=plot(PosBSs_x(:,1),PosBSs_y(:,1),'bp',PosUE(:,1),PosUE(:,2),'r.','MarkerSize', 12);
grid on
hold(hax, 'on')
axis(hax, 'equal')
% Plot the layout as circles
t = linspace(0, 2*pi);
plot(ro * cos(t) + center(1),ro * sin(t) + center(2))

채택된 답변

DGM
DGM 2022년 2월 14일
Here's a start. I used different colors for clarity, but you can change that to whatever you want.
ro=1000; % radius of the layout circle
NumBSs=2; % Number of Base stations
NumUEs=50; %Number of users
center=[0 0]; % center of the circle
maxrange = 1000;
theta_BSs=2*pi*(rand(NumBSs,1)); % distributed random number of Base stations
g = 0.5 * ro + 0.5 * ro * rand(NumBSs,1);
PosBSs_x=center(1)+g.*cos(theta_BSs);
PosBSs_y=center(2)+g.*sin(theta_BSs);
theta1 = rand(NumUEs, 1) * 2*pi; % distributed random number of Users
r1 = ro * sqrt(rand(NumUEs, 1));
PosUE = [r1 .* cos(theta1(:)) + center(1),r1 .* sin(theta1(:)) + center(2)];
% find which UE points are within range of a BS
D = (PosUE(:,1)-PosBSs_x.').^2 + (PosUE(:,2)-PosBSs_y.').^2;
inrange = any(D <= maxrange^2,2);
numinrange = nnz(inrange);
% Initial plot objects
hfig = figure(2);
hax=axes('parent',hfig);
% Plot of deploying points
hdots(1) = plot(PosBSs_x,PosBSs_y,'bp','MarkerSize', 12); hold on
if numinrange > 0
hdots(2) = plot(PosUE(inrange,1),PosUE(inrange,2),'g.','MarkerSize', 12);
end
if numinrange < NumUEs
hdots(3) = plot(PosUE(~inrange,1),PosUE(~inrange,2),'r.','MarkerSize', 12);
end
% Plot the layout as circles
t = linspace(0, 2*pi);
plot(ro * cos(t) + center(1),ro * sin(t) + center(2))
grid on
hold(hax, 'on')
axis(hax, 'equal')
  댓글 수: 8
DGM
DGM 2022년 3월 17일
You should be able to just do a logical combination of the two conditions:
inrange = (mindistD >= maxrange^2) & (mindistD<= maxrangeD2^2);
omar th
omar th 2022년 3월 31일
Thank you so much,
Can I sort these group of assigned point seperately, which means I want to know exactly the group of RED points (as vectors it is not necessary to plot them) that assigned to blue Pentagon seperately ??
Thanks in advance
in this line
plot([PosUE(inrange,1) PosBSs_x(BSidx(inrange))]', ...
[PosUE(inrange,2) PosBSs_y(BSidx(inrange))]','b');

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Multicore Processor Targets에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by