source: proiecte/pmake3d/make3d_original/Make3dSingleImageStanford_version0.1/third_party/opt/yalmip/usertest/distance.m @ 37

Last change on this file since 37 was 37, checked in by (none), 14 years ago

Added original make3d

File size: 1.1 KB
Line 
1function dist=distance(X,x);
2% dist=distance(X,x)
3%
4% computes the pairwise squared distance matrix between any column vectors in X and
5% in x
6%
7% INPUT:
8%
9% X     dxN matrix consisting of N column vectors
10% x     dxn matrix consisting of n column vectors
11%
12% OUTPUT:
13%
14% dist  Nxn matrix
15%
16% Example:
17% Dist=distance(X,X);
18% is equivalent to
19% Dist=distance(X);
20%
21[D,N] = size(X);
22     
23try
24 if(nargin>=2)
25    % PAIRWISE DISTANCES
26  [D,n] = size(x);
27  X2 = sum(X.^2,1);
28  x2 = sum(x.^2,1);
29  dotProd = X'*x;
30  dist = repmat(x2,N,1)+repmat(X2',1,n)-2*dotProd;
31 else   
32  [D,N] = size(X);
33  if(exist('addv') & exist('addh'))
34   X2 = sum(X.^2,1);
35   dist=addh(addv(-2*X'*X,X2),X2);
36  else
37   X2 = repmat(sum(X.^2,1),N,1);
38   dist = X2+X2'-2*X'*X;   
39%   fprintf('Please install addv and addh.\n');
40  end;
41 end;
42 
43catch
44  dist=zeros(N);
45  tic;
46  fprintf('Not enough Memory\nComputing distance line by line ...\n');
47  for i=1:N-1
48    j=(i+1):N;
49    dist(i,j)= ones(1,length(j)).*sum(X(:,i).^2)+sum(X(:,j).^2)-2.*(X(:,j)'*X(:,i))';
50    dist(j,i)=dist(i,j)';   
51  end;
52  fprintf('\n');
53end;
54
Note: See TracBrowser for help on using the repository browser.