Trying to find the Euclidean distance of 2 vectors with different sizes
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
T = [
5.1000 3.5000
6.4000 3.2000
5.4000 3.4000
5.7000 2.8000
5.7000 4.4000
5.6000 2.9000 ];
X = [
5.5000 3.8000
6.4000 2.9000
4.3000 3.0000
5.4000 3.0000
4.5000 1.5000
1.1000 0.1000
1.1000 0.1000 ];
I'm trying to find the euclidean distance between each row of T and each row of X.
This is the method that I have been using to find the euclidean distance and to store the results into an vector, within a nested for loop.
for i=1:1:size(T)
for j=1:1:size(X)
distance( i ,1 ) = sqrt( (( T( i , 1 ) - X ( j , 1 )).^2 ) + (( T( i , 2) - X( j , 2 )).^2) );
end
end
0 commentaires
Réponses (1)
Torsten
le 5 Nov 2022
T =[5.1000 3.5000
6.4000 3.2000
5.4000 3.4000
5.7000 2.8000
5.7000 4.4000
5.6000 2.9000 ];
X =[5.5000 3.8000
6.4000 2.9000
4.3000 3.0000
5.4000 3.0000
4.5000 1.5000
1.1000 0.1000
1.1000 0.1000 ];
D = pdist2(T,X)
0 commentaires
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements 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!