How to find euclidean distances of each column of the two matrices?

조회 수: 25 (최근 30일)
chan
chan 2022년 7월 6일
댓글: Rik 2022년 7월 6일
I have two matrices X and Y, of order 5*3 order
I want to find euclidean distance of 1st column of X matrix and 1st column of Y matrix. Subsequently for 2nd and 3rd column of X and Y matrix.
The solution should be in 1*3 order. How can we proceed this problem?
pdist2(xySet1, xySet2); This solution is for solving eucliden distance of each row of X and Y.
I want to find their distances of each column of the two matrices but I can't understand the help page on pdist.
  댓글 수: 3
chan
chan 2022년 7월 6일
A= 0.5958 0.8909 0.9135
0.5348 0.0558 0.4093
0.0265 0.1159 0.8576
0.0066 0.1568 0.8366
0.4693 0.2467 0.2841
B= 0.4251 0.2552 0.8203
0.3655 0.3306 0.3039
0.4244 0.4263 0.1493
0.4422 0.3184 0.2394
0.0107 0.1467 0.8425
i want to find distance between 1st column of A matrix and 1st column of Y matrix which leads to one single value as solution. similarly for 2nd and 3rd column by applying eucliden distance
After calculating we should get 3 values.
C=[x y z]
How can we proceed this?
Rik
Rik 2022년 7월 6일
I don't understand what you expect to happen, so I hope the solutions below will help.
For 5 pairs of x and y you expect a single distance. What is the distance between 5 points? The solutions below assume you want the sum of the 4 subsequent distances. Do you?

댓글을 달려면 로그인하십시오.

채택된 답변

Chunru
Chunru 2022년 7월 6일
A= [0.5958 0.8909 0.9135
0.5348 0.0558 0.4093
0.0265 0.1159 0.8576
0.0066 0.1568 0.8366
0.4693 0.2467 0.2841];
B= [0.4251 0.2552 0.8203
0.3655 0.3306 0.3039
0.4244 0.4263 0.1493
0.4422 0.3184 0.2394
0.0107 0.1467 0.8425];
d = vecnorm(A-B)
d = 1×3
0.7850 0.7824 1.0908

추가 답변 (1개)

Rohit Kulkarni
Rohit Kulkarni 2022년 7월 6일
편집: Rohit Kulkarni 2022년 7월 6일
Hi ,
You can do like this:
A = [1 2;3 4]
A = 2×2
1 2 3 4
B = [4 2;7 4]
B = 2×2
4 2 7 4
Distance1 = sqrt(sum((A - B) .^ 2))
Distance1 = 1×2
5 0

카테고리

Help CenterFile Exchange에서 Computational Geometry에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by