How to access the data point that has maximum distance using rangesearch()

1 次查看(过去 30 天)
Hi,
I would like to retrieve the data point which has maximum distance from the middle points. This is my code:
fData = [ 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 ];
[n,dim]=size(fData);
r = 0.5;
[zData, mean_array, sd_array] = zscore_rescale(fData);
idx = randsample(n,2);
X = zData(~ismember(1:n,idx),:); % Training data
Y = zData(idx,:) ;
figure('Name','Result');
plot(zData(:,1),zData(:,2),'.k');
hold on;
plot(Y(:,1),Y(:,2),'*r');
[idrx1, dist1] = rangesearch(X,Y,r,'Distance','euclidean');
for j = 1:length(Y)
for dn =1:length(idrx1{j})
if ~isempty(idrx1{j})
plot(X([idrx1{j}],1),X([idrx1{j}],2),'*b','MarkerSize',5,'MarkerFaceColor','b','DisplayName','Imputed Data');
end
end
end
for j = 1:length(Y)
c = Y(j,:);
pos = [c-r (2*r) (2*r)];
rectangle('Position',pos,'Curvature',[1 1])
end
axis square
I would appreciate if anyone could advice on how to access the data point

采纳的回答

KSSV
KSSV 2018-3-23
Two options:
1. Use pdist and pcik the maximum distance
2. Use knnsearch requesting all the nearest neighbors, from here pick the maximum distance index.
  3 个评论
amj
amj 2018-3-23
It is indeed true. Can i put the limit of searching by radius in knnSearch? I dont have any experience in knnsearch

请先登录,再进行评论。

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by