如何计算点之间的距离?

时间:2013-12-10 16:49:14

标签: matlab

我想计算用户位置,接入点和基站之间的距离

figure('Color', 'white')
UserLocationX = randi(50, 1, 50);  
UserLocationY = randi(50, 1, 50);
plot(UserLocationX, UserLocationY, '^-', 'MarkerSize', 5, 'LineWidth', 2), hold on    
AccessPointX = randi(50, 1, 8);
AccessPointY = randi(50, 1, 8);
plot(AccessPointX, AccessPointY, 'go', 'MarkerSize', 5, 'LineWidth', 6), hold on
BaseStationX = 25;
BaseStationY = 25;
plot(BaseStationX, BaseStationY, 'rs', 'MarkerSize', 5, 'LineWidth', 6), hold on, grid on
leg = legend('User Location', 'Access Point', 'Base Station');  
set(leg, 'Location', 'NorthEastOutside')
xlabel('x-candidate')
ylabel('y-candidate')
title('Scenario')

1 个答案:

答案 0 :(得分:0)

使用pdist2

AP和用户之间:

pdist2([AccessPointX(:) AccessPointY(:)],[UserLocationX(:) UserLocationY(:)])

其他情况类似。