Can I sort each of these group associated random points SEPARATELY for each point ?
조회 수: 1 (최근 30일)
이전 댓글 표시
Can I sort these group of assigned point seperatly, 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
the line that I want to change it
plot([PosUE(inrange,1) PosBSs_x(BSidx(inrange))]', ...
[PosUE(inrange,2) PosBSs_y(BSidx(inrange))]','b');
whole code
ro=1000; % radius of the layout circle
NumBSs=6; % Number of Base stations
NumUEs=50; % Number of users
center=[0 0]; % center of the circle
maxrange = 250; % 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')
댓글 수: 0
답변 (1개)
Divyam
2024년 8월 30일
To sort the users assigned to each base station separately you need to find the closest base station for each user and store the data for the base stations accordingly with the data of user location.
Here is the code for your reference:
ro = 1000; % radius of the layout circle
NumBSs = 6; % Number of Base stations
NumUEs = 50; % Number of users
center = [0 0]; % center of the circle
maxrange = 250; % 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 Users are within range of a Base Station
D = (PosUE(:,1) - PosBSs_x.').^2 + (PosUE(:,2) - PosBSs_y.').^2;
[minD, BSidx] = min(D, [], 2);
inrange = minD <= maxrange^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(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');
% Store Users assigned to each Base Station
UEs_per_BS = cell(NumBSs, 1);
for bs = 1:NumBSs
UEs_per_BS{bs} = PosUE(inrange & BSidx == bs, :);
end
% Display the Users assigned to each Base Station
for bs = 1:NumBSs
fprintf('Users assigned to Base Station %d:\n', bs);
disp(UEs_per_BS{bs});
end
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!