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일

2 개 추천

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

Alan David
Alan David 2021년 9월 11일
편집: Alan David 2021년 9월 11일
Hi Akira,
your answer was very helpful but i tried with different coordinate points (attached) which I figure out that it include the point I need to exclude. is it possible to put a condition if that point has connection range of 55 to 85 with at least two point if not exclude it?
the graph you posted is the normal point place but sometimes point being very close or far to other which mean not belong to the cluster
Thanks
Akira Agata
Akira Agata 2021년 9월 13일
Thank you for your feedback.
Question for clarificationn:
When I run my code for the new data, the result is as shown in the figure below.
Obviously, the nodes which have connection range of 55 to 85 with at least two point are nodes 2 and 4.
But when you delete the other nodes (1, 3 and 5), the nodes 2 and 4 will have only one connection.
So, based on your new data, which is the desired output?
(1) Nodes 2 and 4 ? (Because these nodes have at least two connections with other nodes)
(2) None? (Because when delete the nodes 1, 3 and 5, all the remaining nodes have only one connection)
Alan David
Alan David 2021년 9월 15일
Hi Akira,
Sorry for late reply. Yes, the desired output should be node 2 and 4
Thanks
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개)

카테고리

도움말 센터File Exchange에서 Graph and Network Algorithms에 대해 자세히 알아보기

질문:

2021년 9월 11일

댓글:

2021년 9월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by