2011-11-29 74 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