2011-11-29 77 views
1

我需要生成(在Matlab)L的d其必须满足条件在该组的任何两个点之间的距离维空间d(定义如下)点高于某个给定阈值ř如何生成距离它们之间的距离高于某些字段的点?

The set D = {L Union L的组合}。 L的其他各种组合以其平均值生成。例如,点1,5,6的组合生成为(point_1 + point_5 + point_6)/ 3,类似地,组合1,2,5,6生成为(point_1 + point_2 + point_5 + point_6)/ 4。

通常,集合D将具有$ \ sum_ {i = 1}^{L} L C_ {i} $点。

+0

这听起来更像是一个数学问题,而不是Matlab问题。 –

+0

@OliCharlesworth在matlab代码中寻找帮助来实现这个 – Learner

+1

你知道算法是什么吗?我们可以帮助您将算法转换为Matlab代码。 –

回答

1

我做了一个代码(我认为)做你的解释,告诉我你的想法。

nL=6; 
d=2; 
r=0.1; 
L=rand(d,nL); %%% generate nL random d-dimentional points 

Lfinal=[]; 
for nn=1:nL %% for all passible size of subset of (1:nL) 
    sets=nchoosek(1:nL,nn); %% all sub-set of 1:nL of size nn 
    Ls=reshape(L(:,sets'),d,nn,[]); %% the corresponding Ls 
    newL=squeeze(sum(Ls,2))/nn; %% their sums 
    Lfinal=[Lfinal newL]; %% concatante to the final set of Ls. 
end 

L=Lfinal; 
dists=pdist2(L',L'); %%% compute the distances between each point 
dists(dists==0)=inf; %%% fill the diagonal with infinity to not use the distance between a point and it self 
L=L*r/min(dists(:)); %%% multiply the points by "r/min(dists(:))" to make sure all points are at leat at distance r 

L 
+0

你试过吗?它对你有用吗? – Oli

+0

代码运行完全正常。但是,我需要点平均数。例如:对于组合1,2,3,新点是(P1 + p2 + p3)/ 3而不是总和P1 + P2 + P3现在这个新生成的平均点应该与所有点的距离至少是“r”距离,在你的代码中,点与点之间的距离“r”他们的总和,但我需要之间的点和平均。我想我很清楚传达我的要求 – Learner

+0

好吧,我编辑代码 – Oli