comparison 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
comparison
equal deleted inserted replaced
-1:000000000000 0:f0afece42f48
1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2 % COV2CORR
3 % Convert covariance to standard deviation and correlation coefficient
4 %
5 % SigC is a 1-by-n vector with the standard deviation of each process.
6 % CorrC is an n-by-n matrix of correlation coefficients.
7 %
8 % Algorithm
9 %
10 % SigC(i) = sqrt(Covar(i,i))
11 % CorrC(i,j) = Covar(i,j)/(SigC(i)*SigC(j))
12 %
13 % L Ferraioli 10-10-2010
14 %
15 % $Id: cov2corr.m,v 1.1 2010/11/16 16:41:37 luigi Exp $
16 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17
18
19 function [CorrC,SigC] = cov2corr(Covar)
20
21 CorrC = Covar;
22 SigC = sqrt(diag(Covar));
23 for tt=1:size(CorrC,1)
24 for hh=1:size(CorrC,2)
25 CorrC(tt,hh) = Covar(tt,hh)/(sqrt(Covar(tt,tt))*sqrt(Covar(hh,hh)));
26 end
27 end
28 end