Can we assign or associate the random points only that located inside the a specific range ?
1 view (last 30 days)
Show older comments
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))
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/893570/image.png)
0 Comments
Accepted Answer
DGM
on 14 Feb 2022
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 Comments
DGM
on 17 Mar 2022
You should be able to just do a logical combination of the two conditions:
inrange = (mindistD >= maxrange^2) & (mindistD<= maxrangeD2^2);
More Answers (0)
See Also
Categories
Find more on Multicore Processor Targets in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!