Cross correlating matrix for each column
Mostra commenti meno recenti
Hy all, i am a beginer in matlab. I have some problem with cross corelating two matricces, because i have large number of data, i have made a loop model like this:
Load a.dat
Load b.dat
X1=a(:,m)
X2=b(:,m)
For m=1:2;
X=xcorr(x1,x2)
End
Plot(x)
But the answer is undefined variable "m". a & b is a 34x34 matrix,
2 Commenti
Ced
il 21 Gen 2015
Hi
When you include code in your answer, try to use the "code" block (button at the top), it makes it more readable.
So, just repeating your code with some line numbers:
1 Load a.dat
2 Load b.dat
3 X1=a(:,m)
4 X2=b(:,m)
5 for m=1:2;
6 X=xcorr(x1,x2)
7 End Plot(x)
In lines 3 and 4, you are calling a(:,m) and b(:,m), but m is only defined in line 5. See the problem? You need to define m before you use it. Also, be aware that matlab is case-sensitive!
What are you trying to plot? The crosscorrelation of each column of a with each column of b? That's going to be a huge number of lines...
La Ode Marzujriban
il 22 Gen 2015
Risposte (1)
help xcorr
...
xcorr(A), when A is an M-by-N matrix, is a large matrix with
2*M-1 rows whose N^2 columns contain the cross-correlation
sequences for all combinations of the columns of A.
...
So,
X=xcorr([a b]);
but, as ced notes,
size(X) = [2*68-1,34^2]
= [135,1156]
ADDENDUM
Yeah, sorry, I wasn't thinking about it producing the self correlation vectors, too...
[M,N]=size(x,2);
X=zeros(2*M-1,N*N);
k=0;
for i=1:N
for j=1:N
k=k+1;
X(:,k)=xcorr(x(:,i),y(:,j));
end
end
2 Commenti
Ced
il 21 Gen 2015
Yep. That's a bit of an overestimate however, since with xcorr([a b]) you are computing the autocorrelations of A and B too and each crosscorrelation twice.
La Ode Marzujriban
il 22 Gen 2015
Categorie
Scopri di più su Correlation and Convolution in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!