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
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.
Tino
Tino 2019-4-8
Thanks for your swift response
I want use the first row of x and go through all the rows of T
second row will be = sqrt ((6.4 - 5.1)^2 + ((3.2 - 3.8)^2 + ((4.5 - 1.9)^2 + (1.5 - 0.4)^2
each row of X will give (6,4)
Kindly assist me in solving the ussue

请先登录,再进行评论。

采纳的回答

Guillaume
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 个)

类别

Help CenterFile 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!

Translated by