Calculating the differences between XY pairs in a matrix

3 vues (au cours des 30 derniers jours)
Naruto
Naruto le 8 Nov 2020
Commenté : Matt J le 10 Nov 2020
Hello friends,
I have this mega matrix (1000:4) with observations that has 0 and 1 on the last column.
The second and third column contains the observations' x,y coordinates in m distance. I want to create a condition where it can output the rows that include 0, satisfy the condition that the measured distance between an observation of 0 and 1 that were less than 5m and then count the no. of observations that satisfied both conditions.
How could I list them out? I realise that the essential functions that I can use could be for loop, count and else if.
Thanks.

Réponse acceptée

Matt J
Matt J le 8 Nov 2020
xy=M1(:,2:3);
b=M1(:,4);
A=xy(:,b==0);
B=xy(:,b==1);
tf = any(pdist2(A,B)<=5,2);
result=A(tf,:);
  2 commentaires
Naruto
Naruto le 9 Nov 2020
Thanks Matt!
Matt J
Matt J le 10 Nov 2020
You're quite welcome, but please Accept-click the answer to indicate that it solved the problem.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by