Removing far points between vectors
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello, i have 2 very large vectors which represent points in a 3d image, im interested in removing all points from the first vector that are farther then 'distance' from the second vector. for example: let A=(1 1 1, 10 10 10, 20 20 20) and b be (1 1 1, 2 2 2, 3 3 3), and distance be 5, only point 1 1 1 in a is closer then 5 to a certain point in b therefore the result should be C=(1 1 1)
2 commentaires
Réponse acceptée
KL
le 15 Mai 2017
Modifié(e) : KL
le 15 Mai 2017
A=[1 1 1; 10 10 10; 20 20 20]
B = [1 1 1; 2 2 2; 3 3 3]
C = A(sqrt(sum((A-B).^2,2))<=5,:) %edited
3 commentaires
KL
le 15 Mai 2017
Modifié(e) : KL
le 15 Mai 2017
As Jan says, the above works only for the matrices of same size. If you want to compare matrices of different sizes and with all the elements in matrix B, then use the following one.
Arep = kron(A,ones(size(B,1),1));
Brep = repmat(B,size(A,1),1);
dAB = sqrt(sum((Arep-Brep).^2,2));
d = mean(reshape(dAB,fliplr(size(A))))
C = A(d<=5,:)
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Logical 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!