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

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))

 Respuesta aceptada

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 comentarios

First, thank you so much for your response
Is there a way to assign the RED points which are located within the Red STARS range (assume STARS have range (as circle) is 100m raduis), while the other RED points that are located out of the STAR range let them associated to the 'DOT BLACK' which is located in the center and this black dot has raduis 1000m which is ro as mentioned in the code below'' ? In the code below
ro=1000; % radius of the layout circle
NumDrones=2; % Number of Drones
NumUEs=20; %Number of users
center=[0 0]; % center of the circle
theta_Drones=2*pi*(rand(NumDrones,1)); % distributed random number of Drones
g = 0.5 * ro + 0.5 * ro * rand(NumDrones,1); % to make them away from the center of circle
PosDrones_x=center(1)+g.*cos(theta_Drones);
PosDrones_y=center(2)+g.*sin(theta_Drones);
PosBSs=[PosDrones_x PosDrones_y];
theta1 = rand(NumUEs, 1) * 2*pi; % distributed random number of Users
r1 = ro * sqrt(rand(NumUEs, 1));
PosUE_x = [r1 .* cos(theta1(:)) + center(:,1)];
PosUE_y = [r1 .* sin(theta1(:)) + center(:,2)];
PosUE = [r1 .* cos(theta1) + center(1),r1 .* sin(theta1(:)) + center(2)];
plot(PosBSs(:,1),PosBSs(:,2),'rp','MarkerSize', 30);
hold on
plot(PosUE(:,1),PosUE(:,2),'r.','MarkerSize', 12);
hold on
PosgNB_x = [0 0, 0 0].';
PosgNB_y = [0 0, 0 0].';
PosgNB = [PosgNB_x,PosgNB_y];
plot(PosgNB_x.',PosgNB_y.','k.','MarkerSize', 40);
hold on
distances = hypot(PosDrones_x-PosUE(:,1).', PosDrones_y-PosUE(:,2).');
distances1 = hypot(PosgNB_x-PosUE(:,1).', PosgNB_y-PosUE(:,2).');
[~, assigned_BS] = min(distances, [],1);
[~, assigned_BS1] = min(distances1, [],1);
plot([PosUE(:,1) PosDrones_x(assigned_BS)].', [PosUE(:,2) PosDrones_y(assigned_BS)].', ...
'color', [0 0 1]);
plot([PosUE(:,1) PosgNB_x(assigned_BS1)].', [PosUE(:,2) PosgNB_y(assigned_BS1)].', ...
'color', [.5 .5 .5])
grid on
hold on
axis equal
% Plot the layout of network as circle
t = linspace(0, 2*pi);% Plot the layout of network as circle
plot(ro * cos(t) + center(1),ro * sin(t) + center(2))
I'm sorry. I misunderstood the question. This is probably more what you're after. This associates each UE with its closest BS. UEs which are out of range of the BS stars are still associated with the center dot.
ro=1000; % radius of the layout circle
NumBSs=3; % Number of Base stations
NumUEs=50; % Number of users
center=[0 0]; % center of the circle
maxrange = 500; % max range for base stations (stars)
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;
[minD BSidx] = min(D,[],2);
inrange = minD <= maxrange^2;
numinrange = nnz(inrange);
% Initial plot objects
hfig = figure(2);
hax=axes('parent',hfig);
% Plot of deploying points
hold on
plot([PosUE(inrange,1) PosBSs_x(BSidx(inrange))]', ...
[PosUE(inrange,2) PosBSs_y(BSidx(inrange))]','b');
plot([PosUE(:,1) repmat(center(1),NumUEs,1)]', ...
[PosUE(:,2) repmat(center(2),NumUEs,1)]','k');
plot(center(1),center(2),'k.','MarkerSize', 20)
plot(PosBSs_x,PosBSs_y,'bp','MarkerSize', 12)
plot(PosUE(inrange,1),PosUE(inrange,2),'r.','MarkerSize', 12);
plot(PosUE(~inrange,1),PosUE(~inrange,2),'r.','MarkerSize', 12);
% 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')
first I really appreciate your help, but I have another query if you have time to correct me ,
If I assume these BSs as drone or flying objects have height let's say 100m to make something like 3D. Would you correct me if my assumption is wrong. To not disturb you just check change in the lines 18 and 19
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 = 250; % max range for base stations (stars)
h=100; %Hieght of BS
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);
PosDrone = [PosBSs_x PosBSs_y];
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;
PosUAV3D = [PosDrone, h * ones(NumBSs,1)];
D = (PosUE(:,1)-PosUAV3D(:,1).').^2 + (PosUE(:,2)-PosUAV3D(:,2).').^2; % UAV to UE distances
[minD, BSidx] = min(D,[],2);
inrange = minD <= maxrange^2; %if min distance between UEs and drone less
%or equal to the range of drone which is 200m, we consider these distances
%in the range.
%numinrange = nnz(inrange);
%Pos_B_range = sqrt(sum(PosgNB .^ 2, 2));
% Initial plot objects
hfig = figure(2);
hax=axes('parent',hfig);
% Plot of deploying points
hold on
plot([PosUE(inrange,1) PosBSs_x(BSidx(inrange))]',[PosUE(inrange,2) PosBSs_y(BSidx(inrange))]','b');
plot([PosUE(:,1) repmat(center(1),NumUEs,1)]',[PosUE(:,2) repmat(center(2),NumUEs,1)]','k');
plot(center(1),center(2),'k.','MarkerSize', 20) % plot fixed gNB as black dot
plot(PosBSs_x,PosBSs_y,'bp','MarkerSize', 12) % plot drones as blue pentagon
plot(PosUE(inrange,1),PosUE(inrange,2),'r.','MarkerSize', 12); % plot UEs in range of drones as red dots
plot(PosUE(~inrange,1),PosUE(~inrange,2),'r.','MarkerSize', 12); % plot UEs in range of gNB as red dots
% 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')
Sorry about the delay.
You need to take the height into account in the distance calculation. You could do this as you'd started:
PosUAV3D = [PosDrone, h * ones(NumBSs,1)];
PosUE3D = [PosUE, zeros(NumUEs,1)];
D = (PosUE3D(:,1)-PosUAV3D(:,1).').^2 ...
+ (PosUE3D(:,2)-PosUAV3D(:,2).').^2 ...
+ (PosUE3D(:,3)-PosUAV3D(:,3).').^2;
Or you could use a more compact expression for the same.
D = sum((permute(PosUE3D,[1 3 2]) - permute(PosUAV3D,[3 1 2])).^2,3);
It depends how you want to write it. The answers are the same.
I really appreciate that, Now I have another question if you could help me, I want to assume an specific outrange for the BS for exampe mindistD > maxrange^2 and mindistD<maxrange2 but I dont know how to determine that in matlab, its something like closed period
if maxrange=200 and maxrange2=250 I want to assume only the users that fallen betwwen 200 and 250 cannot as well as the users greater than 250.
ro=1000; % radius of the layout circle
NumBSs=3; % Number of Base stations
NumUEs=50; % Number of users
center=[0 0]; % center of the circle
maxrange = 500; % max range for base stations (stars)
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;
[minD BSidx] = min(D,[],2);
inrange = minD <= maxrange^2;
numinrange = nnz(inrange);
% Initial plot objects
hfig = figure(2);
hax=axes('parent',hfig);
% Plot of deploying points
hold on
plot([PosUE(inrange,1) PosBSs_x(BSidx(inrange))]', ...
[PosUE(inrange,2) PosBSs_y(BSidx(inrange))]','b');
plot([PosUE(:,1) repmat(center(1),NumUEs,1)]', ...
[PosUE(:,2) repmat(center(2),NumUEs,1)]','k');
plot(center(1),center(2),'k.','MarkerSize', 20)
plot(PosBSs_x,PosBSs_y,'bp','MarkerSize', 12)
plot(PosUE(inrange,1),PosUE(inrange,2),'r.','MarkerSize', 12);
plot(PosUE(~inrange,1),PosUE(~inrange,2),'r.','MarkerSize', 12);
% 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')
Thanks in advance,I want to consider only the users that are located between these ranges 200m and 250 can be interfered by the Drone Node Not consider all users out of 200 can be interfered by this Drone Node as showed in the figure. I hope this figure let you get my point, please don't hesitate to ask me if you need any clarification
NumDrone=2; % Number of Drone Nodes
NumUEs=50; % Number of gound user Nodes
ro=1000; % Raduis of network layout
center=[0 0]; % Center of network layout circle
h_uav=100; % hieght of Drone Nodes
maxrange=200; % Maximum range of coverage area for Drone Nodes
maxrange1=1000; % maximum range of coverage area for Ground Node (gNB)
maxrangeD2=250; % second coverage range for Drone Nodes
PosgNB_x = (0).';
PosgNB_y = (0).';
PosgNB = [PosgNB_x,PosgNB_y];%Ground Node (gNB)
theta_Drone=2*pi*(rand(NumDrone,1)); % distributed random number of Drone Nodes
g = 0.5 * ro + 0.5 * ro * rand(NumDrone,1); % let the drones deployed away from the center of circle network layout
PosDrone_x=center(1)+g.*cos(theta_Drone); %
PosDrone_y=center(2)+g.*sin(theta_Drone);
PosDrone = [PosDrone_x ,PosDrone_y];
theta1 = rand(NumUEs, 1) * 2*pi; % distributed random number of Users
r1 = ro * sqrt(rand(NumUEs, 1));
PosUE_x = r1 .* cos(theta1(:)) + center(:,1);
PosUE_y = r1 .* sin(theta1(:)) + center(:,2);
PosUE = [PosUE_x,PosUE_y];
PosUAV3D = [PosDrone, h_uav * ones(NumDrone,1)]; % 3D Drone Nodes Positions
PosUE3D = [PosUE, zeros(NumUEs,1)];
dist_D_UE = sum((permute(PosUE3D,[1 3 2]) - permute(PosUAV3D,[3 1 2])).^2,3); % Distance between Drone Nodes and its ground Users
dist_gNB_UE = (PosUE(:,1)-PosgNB_x.').^2 + (PosUE(:,2)-PosgNB_x.').^2; % Distance between Ground Node and its ground Users
dist_gNB_D = hypot(PosDrone_x-PosgNB_x(1,:).', PosDrone_y-PosgNB_y(1,:).'); % Distance between Ground Node and Drone Nodes
[mindistD, assigned_BS] = min(dist_D_UE,[],2); % assigned users to the nearest Drone Nodes
[mindistgNB, assigned_BS1] = min(dist_gNB_UE,[],2); % assigned users to the nearest Ground Node
inrange = mindistD <= maxrange^2; % Condition to make the Drone Nodes associated only the users that located around the Drone Node with 200m
inrangegNB = ~inrange; % Condition to make the Gound Nodes associated the users that located out of the coverage range of Drone Nodes
% Here I am trying to let the Drone Node to consider the users that located
% between 200m and 250m as interfered users
inrange2=mindistD<= maxrangeD2^2;
X=nnz(inrange2);
Y=nnz(inrange);
MidRangD=X-Y;
MidRD=nnz(MidRangD);
%if mindistD > maxrange^2 & mindistD<maxrangeD2
% outrangeD=DORange_I;
%end
%inrangegNB= mindistgNB <= maxrange1^2 | mindistD <= maxrange^2; % interfering dist of DxU
r_B0D0 =dist_gNB_D; % distance between Ground Node and Drone Nodes
r_BxU = dist_gNB_UE(inrange); % distance between interfering Ground Node and user
r_B0U = dist_gNB_UE(inrangegNB); % distance between serving Ground Node and user
r_D0U = dist_D_UE(inrange); % distance between the serving drone Node and users
r_DxU = dist_D_UE(X)-dist_D_UE(Y); % distance between interfering Drone Node and user
You should be able to just do a logical combination of the two conditions:
inrange = (mindistD >= maxrange^2) & (mindistD<= maxrangeD2^2);
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');

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre System-Level Simulation en Centro de ayuda y File Exchange.

Preguntada:

el 14 de Feb. de 2022

Comentada:

el 31 de Mzo. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by