Cross correlation Between two matrices row by row

조회 수: 16 (최근 30일)
Flavia Aluisi
Flavia Aluisi 2017년 2월 23일
편집: Massimo Zanetti 2017년 2월 23일
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?

채택된 답변

Massimo Zanetti
Massimo Zanetti 2017년 2월 23일
편집: Massimo Zanetti 2017년 2월 23일
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.
  댓글 수: 2
Flavia Aluisi
Flavia Aluisi 2017년 2월 23일
Thanks, now is working (sorry I'm starting to use matlab), but I have another question, why if I have a matrix 96*3000 I get xcf 1*41 (all Nan) and lags 1*41 (from -20 to 20)?
Massimo Zanetti
Massimo Zanetti 2017년 2월 23일
편집: Massimo Zanetti 2017년 2월 23일
This is due to the fact that having not supplied the number of lags, MATLAB uses a default value numLags=20. Then, the output size is 20*2+1, accordingly.
This is explained in the help page of the function crosscorr, read carefully paragraphs related to numLags input and xcf,lags outputs.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Correlation and Convolution에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by