View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
Convert covariance matrix to correlation matrix

Be the first to rate this file! 4 Downloads (last 30 days) File Size: 1.76 KB File ID: #20630 Version: 1.0

Convert covariance matrix to correlation matrix


Denis (view profile)


09 Jul 2008 (Updated )

Converts covariance matrix to correlation matrix setting exactly 1-s on its main diagonal

| Watch this File

File Information

The function is "remix" of native matlab cov2corr() function, which produces correlation matrix with elements on its main diagonal slightly greater or less then 1. So it can't be used in various further computations, for example in squareform() function.

The problem can be resolved simply by setting all the diagonal elements to 1 (freaky way) or by using variance instead of std while computing correlation matrix (covariance(x,y)/sqrt(var(x)*var(y)) instead of covariance(x,y)/(std(x)*std(y))).

Required Products Financial Toolbox
MATLAB release MATLAB 7.6 (R2008a)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (2)
18 Jul 2008 denis k


x = [0.1 0.2 0.3; .3 .5 .2; .5 .6 .2; .5 .2 .4];

[std, corMatrix] = cov2corr(cov(x));

diag(corMatrix) == 1

Comment only
15 Jul 2008 Dimitri Shvorob

Really? Can you give an example of a non-unit-diagonal correlation matrix output by cov2corr?

Comment only

Contact us