필터 지우기
필터 지우기

How to improve the distance calculation on two separated datasets

조회 수: 3 (최근 30일)
amj
amj 2018년 2월 24일
편집: amj 2018년 2월 25일
Hi,
Can anyone advice me on how to improve the distance calculation on the 2 separated datasets? My Data:
X = [ 3.6 79
1.8 54
3.333 74
2.283 62
4.533 85
2.883 55
4.7 88
3.6 85
1.95 51
4.35 85
1.833 54
3.917 84
4.2 78
1.75 47
4.7 83
2.167 52
1.75 62
4.8 84
1.6 52
4.25 79
1.8 51
1.75 47
3.45 78
3.067 69
4.533 74
3.6 83
1.967 55
4.083 76
3.85 78
4.433 79
4.3 73
4.467 77
3.367 66
4.033 80
3.833 74
2.017 52
1.867 48
4.833 80
1.833 59
4.783 90 ]
clc;
close all;
figure;
h(1) = plot(X(:,1),X(:,2),'bx');
hold on;
X1 = X(1:3,:);
X2 = X(4:40,:);
h(2) = plot(X1(1:3,1), X1(1:3,2),'rs','MarkerSize',10);
k=5;
[D2 ind] = sort(squeeze(sqrt(sum(bsxfun(@minus,X2,permute(X1,[3 2 1])).^2,2))))
ind_closest = ind(1:k,:)
x_closest = X(ind_closest,:)
for j = 1:length(x_closest);
h(3) =plot(x_closest(j,1),x_closest(j,2),'ko','MarkerSize',10);
end
The output shown as in the picture:
The problem is, the code does not picks the closest data points of red squared data points.
  댓글 수: 2
Image Analyst
Image Analyst 2018년 2월 25일
Too bad. You forgot to attach 'faithful.csv' so now you'll have to wait even longer for an answer.
In the meantime, take a look at pdist2() if you have the Statistics and Machine Learning Toolbox.
amj
amj 2018년 2월 25일
Dear Image Analyst,
I really do apologize for the data. Attached is the data

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Get Started with Statistics and Machine Learning Toolbox에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by