I have matrix F (x,y coordinates), which is 1000*2 matrix. i calculated distances between coordinates using PDIST2 command. i want coordinates which are at distance greater than 22?

F = [x5;y5]'; % x,y coordinates
distances = pdist2(F,F); %% claculating distances between every coordinate to all other coodinates
closepoints = distances > 22; %% checking the condition
result = find(closepoints==1); %%
based on the logical condition how to get the coordinates (x,y) which are grater than 22

4 Kommentare

thank you so much for respoding,
distances(distances>22) is giving distance values. between which coordinates those distances are greater than 22?
So you want to obtain the x and y coordinates when distance is greater than 22 ?

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

One possible solution would be like this:
F = [x5;y5]'; % x,y coordinates
D = pdist(F); % pdist function is suitable in this case
idx = squareform(D) > 22;
[p1,p2] = find(triu(idx));
Then, F(p1(i),:) and F(p2(i),:) (for i = 1, ..., numel(p1)) will give the coordinates (x1,y1) and (x2,y2) whose distance are grater than 22.

7 Kommentare

sir thank you so much for respoding,
Are p1 and p2 are indices correspoding to matrix F??
for i = 1:numel(p1)
xn = F(p1(i),:);
yn = F(p2(i),:);
end
result from the above the above loop is yeilding only two coordinates. i want all such possible coordinates which are at a distance greater than 22 from one coordinate to every other coordinate
i am getting xn is n*2 matrix and yn is n*2 matrix . (n = 474192)
  1. distance between first row of xn and first row of yn is greater than 22.
  2. distance between second row of xn and second row of yn is greater than 22.
  3. and so on.....
at a time it is checking distance with only one coordinte. but i want (x,y) coordinates which are at a distance greater than 22 from each coordinate to every other coodinate. so that all possible distances between all coordinates should be graeter than 22
Let me clarify with the following simple 4 coordinates example (i.e assuming your matrix size of F is 4x2).
In this case, the coordinate D has a distance greater than 22 from all other coordinates. On the other hand, the coordinates C has a distance > 22 against A and D but < 22 against B.
In this case, what you want to do is to find the coordinates D? or to find all the edges that has a distance > 22?
graph.png
coordinate A(x1,y1)
coordinate B(x2,y2)
coordinate C(x3,y3)
coordinate D(x4,y4)
and so on
distance between A to B, A to C and A to D should be greater than 22
distance between B to A, B to C and B to D should be greater than 22
distance between C to A, C to B and C to D should be greater than 22
distance between D to A, D to B and D to C should be greater than 22
and so on
like that how many such coordinates are possible . i want all such coordinates
for example:
In the above graph coordinate B voilates the condition i explainbed above, where as if we remove coordinate B from graph Coordnates A,B,C satisfies the condition i explained above.
In your case F is 4*2, out of four coordinates 3 coordinates are satisfying the condition (all possible distances between every coordinate to all other coordintes is greater than 22)
suppose In my case F is 1000*2 (randomly generated ) . out ofthousand how many such possible coordinates will satisfy the condition

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by