Convert covariance matrix to correlation matrix

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

You are now following this Submission

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))).

Cite As

Denis (2026). Convert covariance matrix to correlation matrix (https://www.mathworks.com/matlabcentral/fileexchange/20630-convert-covariance-matrix-to-correlation-matrix), MATLAB Central File Exchange. Retrieved .

General Information

MATLAB Release Compatibility

  • Compatible with any release

Platform Compatibility

  • Windows
  • macOS
  • Linux
Version Published Release Notes Action
1.0.0.0