xcorr computes the cross correlation sequence which is attained by shifting one sequence with respect to the other, complex conjugating it, taking the element by element product, and summing the result.
You typically want to compute the cross correlation sequence when you want to compute the "correlation" between a time series and shifted versions of another series.
For example, the following shows that y is a delayed version of x and the delay is 5 samples.
rng default;
x = randn(10,1);
y = [zeros(5,1); x];
[C,lags] = xcorr(y,x);
stem(lags,C);
Perhaps what you want is corrcoef() to compute the correlation between two random vectors?
Best Answer