AUTH's THMMY "Parallel and distributed systems" course assignments.
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 

19 行
466 B

  1. function [D2] = dist2(X, Y)
  2. % Calculates the squares of the distances of X and Y
  3. %
  4. % X: A mxd array with m d-dimentional points
  5. % Y: A nxd array with n d-dimentional points
  6. % d: Must be the same
  7. [~, d1] = size(X);
  8. [~, d2] = size(Y);
  9. if d1 ~= d2
  10. error('X,Y column dimensions must match');
  11. end
  12. %D2 = sqrt((X.^2)*ones(d,m) -2*X*Y' + ones(n,d)*(Y.^2)');
  13. D2 = max(sum(X.^2, 2) - 2 * X*Y' + sum(Y.^2, 2)', 0);
  14. D2 = sqrt(D2);
  15. end