how do i find the distance between points
古いコメントを表示
if i have x=[1,5,11,26,46,56,66,76,81];
and I want to find the distance between all these points. eg
1,5 = 4
5,11= 6
46,56=10
and if distances are the same add it to a counter
eg
46,56,66
distance = 10
counter = 3
回答 (1 件)
Image Analyst
2018 年 4 月 23 日
If you have the Statistics and Machine Learning Toolbox, you can get the distance of any element from any other element using pdist():
x = [1,5,11,26,46,56,66,76,81]';
distances1D = pdist(x);
distances = squareform(distances1D)
You get:
distances =
0 4 10 25 45 55 65 75 80
4 0 6 21 41 51 61 71 76
10 6 0 15 35 45 55 65 70
25 21 15 0 20 30 40 50 55
45 41 35 20 0 10 20 30 35
55 51 45 30 10 0 10 20 25
65 61 55 40 20 10 0 10 15
75 71 65 50 30 20 10 0 5
80 76 70 55 35 25 15 5 0
For example to get the distance of the second element (5) to the fourth element (26) look in the second row, fourth column and you'll see it's 21, which is abs(26-5).
カテゴリ
ヘルプ センター および File Exchange で Descriptive Statistics についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!