home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l460 / 2.ddi / DATAFUN.DI$ / STD.M < prev    next >
Encoding:
Text File  |  1993-03-07  |  719 b   |  34 lines

  1. function y = std(x)
  2. %STD    Standard deviation.
  3. %    For vectors, STD(x) returns the standard deviation.
  4. %    For matrices, STD(X) is a row vector containing the
  5. %    standard deviation of each column.
  6. %
  7. %    STD computes the "sample" standard deviation, that
  8. %    is, it is normalized by N-1, where N is the sequence
  9. %    length.
  10. %
  11. %    See also COV, MEAN, MEDIAN.
  12.  
  13. %    J.N. Little 4-21-85
  14. %    Revised 5-9-88 JNL
  15. %    Copyright (c) 1984-93 by The MathWorks, Inc.
  16.  
  17.  
  18. [m,n] = size(x);
  19. if (m == 1) + (n == 1)
  20.     m = max(m,n);
  21.     y = norm(x-sum(x)/m);
  22. else
  23.     avg = sum(x)/m;
  24.     y = zeros(size(avg));
  25.     for i=1:n
  26.         y(i) = norm(x(:,i)-avg(i));
  27.     end
  28. end
  29. if m == 1
  30.     y = 0;
  31. else 
  32.     y = y / sqrt(m-1);
  33. end
  34.