spm_en.m 890 B

1234567891011121314151617181920212223242526272829
  1. function [X] = spm_en(X,p)
  2. % Euclidean normalization
  3. % FORMAT [X] = spm_en(X,[p]);
  4. % X - matrix
  5. % p - optional polynomial detrend [default = []]
  6. %__________________________________________________________________________
  7. %
  8. % spm_en performs a Euclidean normalization setting the column-wise sum of
  9. % squares to unity (leaving columns of zeros as zeros)
  10. %__________________________________________________________________________
  11. % Copyright (C) 2008 Wellcome Trust Centre for Neuroimaging
  12. % Karl Friston
  13. % $Id: spm_en.m 3901 2010-05-27 16:14:36Z karl $
  14. % detrend
  15. %--------------------------------------------------------------------------
  16. if nargin > 1
  17. X = spm_detrend(X,p);
  18. end
  19. % Euclidean normalization
  20. %--------------------------------------------------------------------------
  21. for i = 1:size(X,2)
  22. if any(X(:,i))
  23. X(:,i) = X(:,i)/sqrt(sum(X(:,i).^2));
  24. end
  25. end