我有一個像這樣的軌跡:我們假設每個紅色星形標記都可以將其座標廣播到距離其自己位置5個半徑範圍內的綠色圓圈標記。在matlab中選擇一個特定半徑內的n個點的列表?
我怎樣才能根據上面的說明選擇,每個綠色標記的n個紅點列表。提前致謝。
這是我的代碼,我提到了紅色點和綠色標記的座標。
%% Network Setup
anchor_num=1; % Number of anchor node
node_num=20; % Total nodes
length1=70; % Area length
anchor_x=0; % Intial position of anchor x coordinate
anchor_y=0; % Intial position of anchor y coordinate
anchormove=[];% Anchor trajectory
width=40; % Area width
r = 30;
A = zeros(0,2);
B = zeros(0,2);
C = zeros(0,2);
D = zeros(0,2);
north = [ 0 6.9];
east = [ 6.9 0];
south = [ 0 -6.9];
west = [-6.9 0];
order = 4;
for n = 1:order
AA = [B ; north ; A ; east ; A ; south ; C];
BB = [A ; east ; B ; north ; B ; west ; D];
CC = [D ; west ; C ; south ; C ; east ; A];
DD = [C ; south ; D ; west ; D ; north ; B];
A = AA;
B = BB;
C = CC;
D = DD;
end
% Plot network trajectory
%Mtrix A contains the coordinate of red markers.
A = [0 0; cumsum(A)]
p=plot(A(:,1),A(:,2))
title('Plot of Hilbert trajectory');
set(p,'Color','magenta ','LineWidth',2);
axis([0 100 0 100]);
hold on
% x and y are the coordinates of green markers
x=rand(1,100)*100;
y=rand(1,100)*100;
scatter(x,y)
anchormove(1,:)=A(:,1)'
anchormove(2,:)=A(:,2)'
idx=length(anchormove(1,:));
for i=1:idx-1
% Plot the moving anchor node
Ax=anchormove(1,i);
Ay=anchormove(2,i);
plot(Ax,Ay,'r*');
% Plot transmission range of the anchor node
axis([0 100 0 100])
% hold on
pause(0.1)
%hold off
end