Nearest Neighbor XY plot
이전 댓글 표시
A = [1.5, 5.4; 9.2, 3.3; 6.9, 11.1]
B = [2, 4; 8, 10; 12.9,17.1]
5 radius
댓글 수: 4
DGM
2022년 2월 7일
What is the question?
Keturah Palma
2022년 2월 7일
DGM
2022년 2월 7일
What nearest neighbor function? Are you referring to this?
If so, I'm not really familiar with network theory tools. As A and B are non-integers, they aren't indices; what are they?
Keturah Palma
2022년 2월 7일
답변 (1개)
Not sure what function you're talking about. If you just want to find points in Set A that are closer than 5 to points in Set B, you can do this:
markerSize = 40;
A = [1.5, 5.4; 9.2, 3.3; 6.9, 11.1]
B = [2, 4; 8, 10; 12.9,17.1]
% Plot A
plot(A(:, 1), A(:, 2), 'r.', 'MarkerSize', markerSize);
hold on;
% Plot B
plot(B(:, 1), B(:, 2), 'b.', 'MarkerSize', markerSize);
grid on;
distances = pdist2(A, B)
for row = 1 : size(distances, 1)
[r, c] = find(distances(row, :) <= 5);
for k = 1 : length(c)
xCoords = [A(row, 1), B(c(k), 1)];
yCoords = [A(row, 2), B(c(k), 2)];
line(xCoords, yCoords, 'Color', 'm', 'LineWidth', 2)
fprintf('Drawing line between (%.1f, %.1f) and (%.1f, %.1f). The distance is %.3f.\n', ...
A(row, 1), A(row, 2), B(c(k), 1), B(c(k), 2), distances(row, c(k)))
end
end
카테고리
도움말 센터 및 File Exchange에서 Nearest Neighbors에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
