我通过散射算法随机生成了3组点,算法是
M = randi(1000,200);
AP = randi(1000,12);
BS = randi(1000,7);
scatter(M(:,1),M(:,20),21,'b.'); hold on
scatter(AP(:,1),AP(:,9),80,'k*');hold on
scatter(BS(:,1),BS(:,4),'r');hold off
现在,我必须设置AP的覆盖范围并分析AP和M之间的距离,该距离在覆盖范围内。任何人都可以帮助我吗?
答案 0 :(得分:0)
首先提取AP的覆盖范围:
ExtractedM=[M(:,1) M(:,20)];
ExtractedAP=[AP(:,1) AP(:,9)];%Just creating two different matrices for plotted points
%calculating coverage area of AP i.e. bounding box for coordinates of AP
yMax=max(ExtractedAP(:,2));
yMin=min(ExtractedAP(:,2));
xMax=max(ExtractedAP(:,1));
xMin=min(ExtractedAP(:,1));
%Finding the points from M which lie in the coverage area of AP
[positionBoundedPointsMx1,dummy]=find(ExtractedM(:,1)>=xMin & ExtractedM(:,1)<=xMax);
[positionBoundedPointsMx2,dummy]=find(ExtractedM(:,2)>=yMin & ExtractedM(:,2)<=yMax);
positionBoundedPointsMx=intersect(positionBoundedPointsMx1,positionBoundedPointsMx2,'rows');
boundedPointsM=ExtractedM(positionBoundedPointsMx,:);
%Making sure that correct sets of points in M have been extracted
scatter(M(:,1),M(:,20),21,'b.'); hold on
scatter(AP(:,1),AP(:,9),80,'k*');hold on
scatter(BS(:,1),BS(:,4),'r');hold on;
scatter(boundedPointsM(:,1),boundedPointsM(:,2),'ko');
M中的提取点由黑色圆圈内的蓝点表示。它看起来是正确的,因为M中的所有点都位于AP的覆盖范围内。
现在,我不确定你想要计算什么。假设您只想计算两点之间的欧几里德距离,我将ExtractedAP
和boundedPointsM
转换为向量并使用pdist2
ExtractedAP_Vec=ExtractedAP(:); %24x1 vector
boundedPointsM_Vec=boundedPointsM(:); %224x1 vector
%calculate distance between each point of 'ExtractedAP_Vec' and every point in 'boundedPointsM_Vec'.
dist_AP_M=pdist2(ExtractedAP_Vec,boundedPointsM_Vec);
P.S。绘制散点图并自行验证。我不能在这里发布图片,抱歉。