This MATLAB function converts standard deviation and correlation to covariance
INPUTS:
psigma = vector of standard deviations for each of any number of variables or parameters
prho = correlation matrix of the correlations between each each variable or parameter
OUTPUTS:
pcov = covariance matrix between variables or parameters
EXAMPLE:
load hospital
X = [hospital.Weight hospital.BloodPressure];
% Find the correlation matrix for the variables X:
prho = corrcoef(X)
% prho =
% 1.0000 0.1558 0.2227
% 0.1558 1.0000 0.5118
% 0.2227 0.5118 1.0000
% Find the standard deviations of each variable X
psigma = std(X)
% psigma =
% 26.5714 6.7128 6.9325
% Find the covariance matrix between variables X:
pcov = covcorr(psigma,prho)
% pcov =
% 706.0404 27.7879 41.0202
% 27.7879 45.0622 23.8194
% 41.0202 23.8194 48.0590
引用格式
Gregory Pelletier (2024). Covariance from standard deviation and correlation (covcorr) (https://www.mathworks.com/matlabcentral/fileexchange/158046-covariance-from-standard-deviation-and-correlation-covcorr), MATLAB Central File Exchange. 检索时间: .
MATLAB 版本兼容性
创建方式
R2023b
兼容任何版本
平台兼容性
Windows macOS Linux标签
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!