total_matrix = zeros(8,8);
for i=1:vec_num
for j=1:vec_num
total_matrix = total_matrix + x(:,i)*x(:,j)';
end
end
total_matrix = total_matrix / (vec_num*vec_num);
%%
total_matrix is the autocorrelation matrix.
Sounds like you are looking for correlation coefficients. If so, try 'help corrcoef'. Otherwise, try 'help corrmtx' if you have signal processing toolbox.
Yi
You are attempting to compute a sample correlation matrix, but you haven't subtracted out the sample means. Of course, using 'randn' should give a theoretical mean of zero, but that wouldn't be true of an actual sample in general. Also theoretically there would be no cross correlation, but again that will not be strictly true of a sample.
If you use the matlab 'corrcoef' function beware that your matrix x is the transpose of what it expects. 'corrcoef' expects the rows to be observations (eight variable values) and the columns to be variables (1000 each,) so your x would give a 1000 x 1000 matrix unless you did a transpose.
Roger Stafford
Actually there is more wrong with your calculations than I stated. 1) There should only be a single, not a double, summation over the columns of x. 2) You are dividing by vec_num instead of vec_num-1 for unbiased values. 3) Finally you haven't divided by the standard deviations so as to get a diagonal of all ones, so you are just getting covariances, not correlations.
Roger Stafford