Trying to find the Euclidean distance of 2 vectors with different sizes
4 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Torsten
2022-11-5
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!