我用以下方法开发了这个功能:
Point = [2,11]
和
vector_X = [1,9;7,8;2,7;4,7;6,7;8,7;5,6;5,5;2,3;4,3;5,3;6,3;1,2;5,1];
和
MinPts = 3;
功能:
function Distance = MutualReachabilityDistance(Point,vector_X,MinPts)
M1 = pdist2(Point,vector_X);
[~, dist1] = knnsearch(Point, vector_X, 'k', MinPts+1);
core1 = max(dist1).*ones(1,length(vector_X(:,1)));
for i=1:length(vector_X(:,1))
[~, dist2] = knnsearch(vector_X(i,:), vector_X, 'k', MinPts+1);
core_X(1,i) = max(dist2);
end
Distance = max(M1,core1);
Distance = max(Distance,core_X);
我用这一行得到了这个错误:
test = MutualReachabilityDistance(Point,vector_X,MinPts);
祝你好运
答案 0 :(得分:1)
我的代码中没有任何错误。错误消息可能是由于测试变量,它是相同数字的重复。为了避免它改变函数的最后两行,如下所示
function Distance = MutualReachabilityDistance(Point,vector_X,MinPts)
M1 = pdist2(Point,vector_X);
[~, dist1] = knnsearch(Point, vector_X, 'k', MinPts+1);
core1 = max(dist1).*ones(1,length(vector_X(:,1)));
for i=1:length(vector_X(:,1))
[~, dist2] = knnsearch(vector_X(i,:), vector_X, 'k', MinPts+1);
core_X(1,i) = max(dist2);
end
Distance = max(M1,core1);
Distance = max(Distance,core_X);
end