norm3fit.m 822 B

123456789101112131415161718192021222324252627
  1. function [mu C] = norm3fit(W, box, step)
  2. % function [mu C] = norm3fit(W, box, step)
  3. %
  4. % W: 3D matrix of functional values (weights)
  5. % box: [xmin ymin zmin xlen ylen zlen]
  6. % step: [xstep ystep zstep]
  7. %
  8. % returns the mean and covariance matrix
  9. W = W/sum(W(:));
  10. [X Y Z] = ndgrid(box(1):step(1):box(1)+box(4), ...
  11. box(2):step(2):box(2)+box(5), ...
  12. box(3):step(3):box(3)+box(6));
  13. mu = [sum(X(:).*W(:)) sum(Y(:).*W(:)) sum(Z(:).*W(:))];
  14. varx = sum((X(:) - mu(1)).^2 .* W(:));
  15. vary = sum((Y(:) - mu(2)).^2 .* W(:));
  16. varz = sum((Z(:) - mu(3)).^2 .* W(:));
  17. varxy = sum((X(:) - mu(1)).*(Y(:) - mu(2)) .* W(:));
  18. varxz = sum((X(:) - mu(1)).*(Z(:) - mu(3)) .* W(:));
  19. varyz = sum((Y(:) - mu(2)).*(Z(:) - mu(3)) .* W(:));
  20. C = [varx varxy varxz; ...
  21. varxy vary varyz; ...
  22. varxz varyz varz];