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

  1. function xy = corrcoef(x,y)
  2. %CORRCOEF Correlation coefficients.
  3. %    CORRCOEF(X) is a matrix of correlation coefficients formed
  4. %    from array X whose each row is an observation, and each
  5. %    column is a variable.
  6. %    CORRCOEF(X,Y) is the same as CORRCOEF([X Y]).
  7. %
  8. %    If C is the covariance matrix, C = COV(X), then CORRCOEF(X) is
  9. %    the matrix whose (i,j)'th element is
  10. %
  11. %                C(i,j)/SQRT(C(i,i)*C(j,j)).
  12. %
  13. %    See also COV, STD.
  14.  
  15. %    J. Little 5-5-86
  16. %    Revised 6-9-88 LS
  17. %    Copyright (c) 1984-93 by The MathWorks, Inc.
  18.  
  19. if nargin > 1
  20.     c = cov(x,y);
  21. else
  22.     c = cov(x);
  23. end
  24. d = diag(c);
  25. xy = c./sqrt(d*d');
  26.