cov2corr — Convert a covariance matrix to a correlation matrix.
cov2corr(C) is a RunMat alias that applies the same covariance-to-correlation conversion as corrcov(C). [R,sigma] = cov2corr(C) also returns sqrt(diag(C)) as an n-by-1 standard-deviation vector.
Syntax
R = cov2corr(C)
[R, sigma] = cov2corr(C)Inputs
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
C | Any | Yes | — | Square covariance matrix. |
Returns
| Name | Type | Description |
|---|---|---|
R | NumericArray | Correlation matrix corresponding to the covariance matrix. |
sigma | NumericArray | Column vector of standard deviations computed from diag(C). |
Returned values from cov2corr depend on how many outputs the caller requests.
Errors
| Identifier | When | Message |
|---|---|---|
RunMat:cov2corr:InvalidArgument | Input is nonnumeric, complex, not single/double precision, non-square, has negative variances, violates covariance bounds, or too many arguments/outputs are supplied. | covariance conversion: invalid argument |
RunMat:cov2corr:Internal | Internal tensor allocation fails. | covariance conversion: internal error |
How cov2corr works
Cmust be a real numeric square matrix stored as double or single precision. Scalar numeric values are accepted as 1-by-1 covariance matrices.- The diagonal entries of
Care interpreted as variances and must be nonnegative. - RunMat validates symmetry within floating-point tolerance before converting.
- RunMat rejects covariance entries whose magnitude exceeds the variance-implied pairwise bound
sqrt(C(i,i)*C(j,j)). - Entries involving a zero-variance variable produce
NaNbecause the correlation denominator is zero. - Real gpuArray inputs stay resident when the active provider implements covariance-to-correlation conversion.
Example
Convert covariance to correlation
C = [16 4; 4 25];
R = cov2corr(C)Expected output:
R = [1 0.2; 0.2 1]Using cov2corr with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how cov2corr changes the result.
Run a small cov2corr example, explain the result, then change one input and compare the output.
FAQ
Is cov2corr different from corrcov?⌄
No. In RunMat, cov2corr is an alias for the same covariance-to-correlation conversion as corrcov. It is documented as a RunMat alias rather than an official MathWorks API.
Related Stats functions
Summary
binocdf · boxplot · cdf · cdfplot · chi2cdf · corr · corrcoef · corrcov · cov · dummyvar · ecdf · filloutliers · fitdist · geomean · grpstats · harmmean · icdf · isoutlier · kstest · kurtosis · lsline · mad · mode · nanmax · normalize · normcdf · norminv · normpdf · onehotdecode · onehotencode · pdf · prctile · quantile · refline · rmse · skewness · tabulate · tcdf · tiedrank · tinv · tpdf · ttest2 · wblinv
Ml
bayesopt · classify · confusionmat · crossvalind · cvpartition · fitclinear · fitctree · fitlm · kmeans · knnsearch · lasso · lassoglm · linkage · lscov · mnrfit · optimizableVariable · pdist · pdist2 · perfcurve · predict · regress · ridge · squareform · test · training · tsne
Random
binornd · bootstrp · datasample · dividerand · exprnd · gamrnd · lhsdesign · mvnrnd · normrnd · random · randsample · rng · trnd · unidrnd · unifrnd · wblrnd
Hist
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how cov2corr is executed, line by line, in Rust.
- View the source for cov2corr in Rust on GitHub
- Learn how the RunMat runtime works
- Found a bug? Open an issue with a minimal reproduction.
About RunMat
RunMat is an open-source runtime that executes MATLAB-syntax code blazing on any GPU. It is licensed under the Apache 2.0 license.
- RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
- Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.