get the distances between points

1 回表示 (過去 30 日間)
Alan David
Alan David 2021 年 9 月 11 日
コメント済み: Alan David 2021 年 9 月 16 日
Hi,
I have multiple coordinates points which I want to get the minimum distance between point 1 to nearest other point and so on and if the distance not in the range of 55 to 85 exclude that point from cluster. I tried pdist and pdist2 and it gave me the distance from point 1 to others I don't know how to include only the desired distance which is only between 55 to 85
I attached the mat file for the coordinate points
Thanks for helping

採用された回答

Akira Agata
Akira Agata 2021 年 9 月 11 日
How about the following solution?
load('xy_coordinate.mat');
% Calculate distance between each node
D = pdist(xy);
% Convert variable D into square form
Z = squareform(D);
% Extract edges having length of 55~85
idx = Z >= 55 & Z <= 85;
Z(~idx) = 0;
% Convert it into graph object
G = graph(Z);
% Visualize the result
figure
plot(G,'EdgeLabel',G.Edges.Weight)
  5 件のコメント
Akira Agata
Akira Agata 2021 年 9 月 16 日
Hi @Alan David-san,
OK. Then, it's a piece of cake!
Please check the degree of each nodes and extract the nodes where degree >= 2.
Here is an example:
load('xy_corr.mat');
% Calculate distance between each node
D = pdist(xy);
% Convert variable D into square form
Z = squareform(D);
% Identify edges having distance of [55, 85]
idx = Z >= 55 & Z <= 85;
Z(~idx) = 0;
% Convert it into graph object
G = graph(Z);
% Check degree of graph nodes
d = degree(G);
% Find the node with degree of >= 2
idx = d >= 2;
disp(find(idx))
Alan David
Alan David 2021 年 9 月 16 日
Thanks Akira,
You've been very helpful.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Import and Network Parameters についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by