0001 function d = distanz(x,y,type)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024 if exist('type')~=1|isempty(type), type = 3; end
0025 switch type
0026 case 1
0027 if exist('y')~=1|isempty(y)
0028
0029 [rx,cx] = size(x);
0030 d = zeros(cx,cx);
0031 nuller = zeros(cx,1);
0032 for c = 1:cx
0033 d(c,:) = sum((x-x(:,c+nuller)).^2,1);
0034 end
0035 else
0036
0037 [rx,cx] = size(x);
0038 [ry,cy] = size(y);
0039 if rx~=ry, error('x and y do not fit'), end
0040 d = zeros(cx,cy);
0041 if cx>cy
0042 nuller = zeros(cx,1);
0043 for c = 1:cy
0044 d(:,c) = sum((x-y(:,c+nuller)).^2,1)';
0045 end
0046 else
0047 nuller = zeros(cy,1);
0048 for c = 1:cx
0049 d(c,:) = sum((x(:,c+nuller)-y).^2,1);
0050 end
0051 end
0052 end
0053
0054 case 2
0055 if exist('y')~=1|isempty(y)
0056
0057 [rx,cx] = size(x);
0058 d = zeros(cx,cx);
0059 nuller = zeros(cx,1);
0060 for c = 1:cx
0061 d(c,:) = sum((x-repmat(x(:,c),[1 cx])).^2,1);
0062 end
0063 else
0064
0065 [rx,cx] = size(x);
0066 [ry,cy] = size(y);
0067 if rx~=ry, error('x and y do not fit'), end
0068 d = zeros(cx,cy);
0069 if cx>cy
0070 nuller = zeros(cx,1);
0071 for c = 1:cy
0072 d(:,c) = sum((x-repmat(y(:,c),[1 cx])).^2,1)';
0073 end
0074 else
0075 nuller = zeros(cy,1);
0076 for c = 1:cx
0077 d(c,:) = sum((repmat(x(:,c),[1 cy])-y).^2,1);
0078 end
0079 end
0080 end
0081
0082 case 3
0083 if exist('y')~=1|isempty(y)
0084
0085 cx = size(x,2);
0086 xx = sum(x.*x,1); xz = x'*x;
0087 d = abs(repmat(xx',[1 cx]) - 2*xz + repmat(xx,[cx 1]));
0088 else
0089
0090 [rx,cx] = size(x);
0091 [ry,cy] = size(y);
0092 if rx~=ry, error('x and y do not fit'), end
0093 xx = sum(x.*x,1); yy = sum(y.*y,1); xy = x'*y;
0094 d = abs(repmat(xx',[1 cy]) + repmat(yy,[cx 1]) - 2*xy);
0095 end
0096 end
0097
0098 d = sqrt(d);
0099