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
2019 年 3 月 13 日
distmat = B(:,4:7)-repmat(A,4,1);
dist = vecnorm(distmat.')
4 件のコメント
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.')
その他の回答 (1 件)
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;
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!