|
|
[m,n] = size(A);, K; i! W. @2 D* Y3 n
output = zeros(1,m);
! X$ U; p( Y* u. ~& V1 _for loop = 1:m# k2 P$ ~6 { g
data = [A(loop,: );B(:,[1,2])];
$ K! c2 B X9 S( m7 j* P dD = squareform(pdist(data));%compute the euclidean distance
5 y( L6 @( e1 C6 ^. LD = D(1,2:end); % get the distance from point in B to the loop point in A
& f, ~5 g& m/ ?( f' rindex = find(D == min(D));
$ J- v' n" {% d4 s( koutput(loop) = B(index,3);
# r8 t$ L3 h4 A: n2 nend# D3 c+ _) x; G, E& ]5 b) i
. z D' P8 i8 h9 p- }4 f- U$ r$ g你可以试试这个 |
|