i am trying to find the euclidean distance of 2 vector with different sizes
2 次查看(过去 30 天)
显示 更早的评论
T =
5.1000 3.5000 1.4000 0.2000
6.4000 3.2000 4.5000 1.5000
5.4000 3.4000 1.7000 0.2000
5.7000 2.8000 4.5000 1.3000
5.7000 4.4000 1.5000 0.4000
5.6000 2.9000 3.6000 1.3000
X =
5.5000 3.8000 1.9000 0.4000
6.4000 2.9000 4.3000 1.3000
4.3000 3.0000 1.1000 0.1000
5.4000 3.0000 4.5000 1.5000
I want to use this method to find euclidean distance for each row of T and X in such a way use the each row of X to T(6,4)
for example first row will be = sqrt ((5.5 - 5.1)^2 + ((3.5 - 3.8)^2 + ((1.4 - 1.9)^2 + 0.2 -0.4)^2....................first row to the 24th row ( the number of row to obtain is 24)
Kindly get back to me thank
2 个评论
Adam
2019-4-8
The first row is clear enough, and up to the 4th row in your example posted above, but it's not clear what you are expecting where you have more rows in T than in X.
采纳的回答
Guillaume
2019-4-8
编辑:Guillaume
2019-4-8
I'm also not clear on what you're asking. If you want to find the euclidean distance between each row of T and each row of X, then this is easily done:
T = [
5.1000 3.5000 1.4000 0.2000
6.4000 3.2000 4.5000 1.5000
5.4000 3.4000 1.7000 0.2000
5.7000 2.8000 4.5000 1.3000
5.7000 4.4000 1.5000 0.4000
5.6000 2.9000 3.6000 1.3000];
X = [
5.5000 3.8000 1.9000 0.4000
6.4000 2.9000 4.3000 1.3000
4.3000 3.0000 1.1000 0.1000
5.4000 3.0000 4.5000 1.5000];
distance = sqrt(sum((permute(T, [1 3 2]) - permute(X, [3 1 2])) .^ 2, 3))
distance(r, c) is then the distance between T(r, :) and X(c, :)
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Statistics and Machine Learning Toolbox 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!