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

NameTypeRequiredDefaultDescription
CAnyYesSquare covariance matrix.

Returns

NameTypeDescription
RNumericArrayCorrelation matrix corresponding to the covariance matrix.
sigmaNumericArrayColumn vector of standard deviations computed from diag(C).

Returned values from cov2corr depend on how many outputs the caller requests.

Errors

IdentifierWhenMessage
RunMat:cov2corr:InvalidArgumentInput 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:InternalInternal tensor allocation fails.covariance conversion: internal error

How cov2corr works

  • C must 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 C are 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 NaN because 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.

Open-source implementation

Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how cov2corr is executed, line by line, in Rust.

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.

Getting started · Benchmarks · Pricing

Download RunMat

Download RunMat for full performance, or use RunMat in your browser for zero setup.