corrcoef

Matrix of Pearson correlation coefficients.

Category: Data Import and Analysis > Descriptive Statistics

Syntax

R = corrcoef(A)

Correlation between the columns of A.

R = corrcoef(x, y)

Correlation between two variables, as a 2-by-2 matrix.

Description

The Pearson coefficient is the covariance of two variables divided by the product of their standard deviations. It measures linear association only: values near 1 or -1 mean the points lie close to a line, and values near 0 mean there is no linear trend.

For two vectors the answer is a 2-by-2 matrix, and the correlation is the off-diagonal entry R(1,2).

Input arguments

A
Matrix whose columns are variables and rows are observations.
x, y
Vectors with the same number of elements.

Output arguments

R
Symmetric matrix with ones on the diagonal; R(i,j) is the correlation of variables i and j, between -1 and 1.

Example

Two variables

x = [1 2 3 4];
y = [2 4 5 9];
R = corrcoef(x, y)
r = R(1,2)
Output
R = 2×2

    1.0000    0.9648
    0.9648    1.0000
r = 0.9648

See also

cov std polyfit