How to calculate the distance

2 次查看(过去 30 天)
I have table B as given bellow. I have another point for example A=[100 111 80 120]. I want to calculate the euclidean distance between A and the columns (fourth, fifth, sixth and seventh) of B for each row.
B=
0 1 0 153 119 97 148
0 1 0 148 122 98 149
0 1 0 163 126 95 150
0 1 0 188 150 118 178
  2 个评论
Torsten
Torsten 2019-3-13
编辑:Torsten 2019-3-13
... for each row ? What do you mean ?
Asad Abbas
Asad Abbas 2019-3-13
matric B has four rows. I want to claculate the deistance between A and the last four columns of B
such as distance between
153 119 97 148 and A=[100 111 80 120]
148 122 98 149 and A=[100 111 80 120]
163 126 95 150 and A=[100 111 80 120]
188 150 118 178 and A=[100 111 80 120]

请先登录,再进行评论。

采纳的回答

Torsten
Torsten 2019-3-13
distmat = B(:,4:7)-repmat(A,4,1);
dist = vecnorm(distmat.')
  4 个评论
Torsten
Torsten 2019-3-13
Works for me:
A = [100 111 80 120];
B = [0,1, 0, 153, 119, 97, 148;...
0, 1, 0, 148, 122, 98, 149;...
0, 1, 0, 163, 126, 95, 150;...
0, 1, 0, 188, 150, 118, 178];
distmat = B(:,4:7)-repmat(A,4,1);
dist = vecnorm(distmat.')
Asad Abbas
Asad Abbas 2019-3-13
Now its working.
Thank you so much.

请先登录,再进行评论。

更多回答(1 个)

Alex Mcaulley
Alex Mcaulley 2019-3-13
What do you mean by distance? euclidean, just the difference...
If you are looking for the difference:
B = [0 1 0 153 119 97 148;
0 1 0 148 122 98 149;
0 1 0 163 126 95 150;
0 1 0 188 150 118 178];
A = [100 111 80 120];
res = B(:,4:7)-A;

类别

Help CenterFile Exchange 中查找有关 Polynomials 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by