|
[m,n] = size(A);
. a% c- L% P$ X! @output = zeros(1,m);
) U% ^$ h, W) c1 m2 s8 ]for loop = 1:m
4 d' k: R' y5 bdata = [A(loop,: );B(:,[1,2])];0 }( V {' w1 n
D = squareform(pdist(data));%compute the euclidean distance* O y/ W6 ~; q; m- m# Z! a
D = D(1,2:end); % get the distance from point in B to the loop point in A5 i" B% h& p! @! P/ V
index = find(D == min(D));+ e" m2 f- B2 W2 F0 n$ i. N* d
output(loop) = B(index,3);
2 b6 S' C+ h$ x5 b' Oend
* e' I& h: C* b' T
, C( w, G9 l+ ~1 M7 _4 o+ e/ m; V你可以试试这个 |
|