Mercurial > hg > ltpda
diff m-toolbox/classes/+utils/@math/cov2corr.m @ 0:f0afece42f48
Import.
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Wed, 23 Nov 2011 19:22:13 +0100 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/m-toolbox/classes/+utils/@math/cov2corr.m Wed Nov 23 19:22:13 2011 +0100 @@ -0,0 +1,28 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% COV2CORR +% Convert covariance to standard deviation and correlation coefficient +% +% SigC is a 1-by-n vector with the standard deviation of each process. +% CorrC is an n-by-n matrix of correlation coefficients. +% +% Algorithm +% +% SigC(i) = sqrt(Covar(i,i)) +% CorrC(i,j) = Covar(i,j)/(SigC(i)*SigC(j)) +% +% L Ferraioli 10-10-2010 +% +% $Id: cov2corr.m,v 1.1 2010/11/16 16:41:37 luigi Exp $ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + +function [CorrC,SigC] = cov2corr(Covar) + + CorrC = Covar; + SigC = sqrt(diag(Covar)); + for tt=1:size(CorrC,1) + for hh=1:size(CorrC,2) + CorrC(tt,hh) = Covar(tt,hh)/(sqrt(Covar(tt,tt))*sqrt(Covar(hh,hh))); + end + end +end \ No newline at end of file