MATLAB: Cross correlation Between two matrices row by row

correlation

Good morning, I have a problem with the cross correlation (crosscorr command), I'm trying to do a cross correlatation btw 2 matrices with dimension 96*3000, and I wrote this small loop:
[r, c] = size(AinO1_correct);
for i=1:r
[xcf,lags,bounds]=crosscorr(AinO1_correct(i,2) , AinO1_incorrect(:,2));
correlationAinO1 = z';
end
but i got this error 'First series must be a vector.' I don't know what is wrong could please help me?

Best Answer

There are some issues in your code.
  1. crosscorr function requires two vector inputs. Ain01_correct(i,2) it is not (it is a number). Notice also that AinO1_incorrect(:,2) is just the second column of your matrix (not a row).
  2. correlationAinO1 = z'; what is that???
I assume what you want is:
[r, c] = size(AinO1_correct);
for i=1:r
[xcf,lags,bounds]=crosscorr(AinO1_correct(i,:) , AinO1_incorrect(i,:));
end
notice that arguments of crosscorr function are row vectors from your matrices.
IMPORTANT check the size of the two matrices is the same before running the code.
Related Question