Trying to find the Euclidean distance of 2 vectors with different sizes
4 views (last 30 days)
Show older comments
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 Comments
Answers (1)
Torsten
on 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 Comments
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!