MATLAB: What is different between ‘corr’ and ‘corrcoef’

corrcorrcoefcorrelation coefficientMATLABStatistics and Machine Learning Toolbox

I wanna compute correlation coefficient of two matrices,which function should I use? Thanks previously.

Best Answer

If you want a single correlation coefficient between two matrices, then neither, see corr2.
For two matrices, corr() returns the pairwise correlation between the columns of the two matrices if that is what you want.
If you input two matrices into corrcoef(), it converts the matrices to column vectors first and then just computes the correlation coefficient between those two vectors.
So for example:
X = randn(8,8);
Y = randn(8,8);
corrcoef(X,Y)
is the same as
X1 = X(:);
Y1 = Y(:);
corrcoef(X1,Y1)