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!