필터 지우기
필터 지우기

i am trying to find the euclidean distance of 2 vector with different sizes

조회 수: 3 (최근 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에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by